Issue
So I have a loading activity that needs to load every time a user opens the program. I have the loading activity as the main activity in the manifest. If the loading activity is successful, it launches a HomeActivity. If I hit the back button from the HomeActivity, it will fire off the LoadingActivity when I try to access the app again. If I hit the home button from the HomeActivity, launching it goes back to the HomeActivity without going to the LoadingActivity.
I have tried adding those, clearTaskOnLaunch and FinishOnTaskLaunch. I have tried capturing the home button, that doesn't work. I cannot finish onPause or onStop as I have the HomeActivity start an activity that opens up on top of the HomeActivity then drop back down to it. Any ideas on what to do? Heres the manifest, still learning android manifest stuff so don't kill me.
<activity
android:name=".start.LoadingActivity"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:label="@string/title_activity_home"
android:screenOrientation="nosensor"
>
</activity>
Solution
Home button default function is to go to the home screen without killing the activity. Android users expect to the find the screen they were on when the come back to the app after pressing home button. So I recommned you change your design. But if you must do it your way, here's one logic you can use.
Every time you launch the main activity set a flag in shared preferences, say from_main=true. Then, in your onPause for main activity, check if from_main is true. If it's true call finish(). If not, don't do anything.
Now, when you launch another activity from your main activity set the flag from_main in shared preferences to false.
This way, you'll now if onPause is being called before launching the other activity from main or after launching it. If it's before launching it, then it won't finish main and you can drop back down to it. If it's after launching it, then it'll finish the main activity.
Answered By - Anup Cowkur
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.