Issue
I've 3 activities:
Main activity -> start activity 2
activity 2 -> plays a sound with MP, if finished start activity 3
activity 3 -> plays another sound with MP, if finished start Main.
Now I am back at the main-activity, I click on the return button and come back to activity 3, but I want to exit the app, if I click on the return in the main activity. How can I handle this?
Solution
Add this to your main activity definition in your manifest: android:launchMode="singleTask"
What is happening in your example is you are adding Activities to your stack as you call startActivity
at each level. If you call startActivity
to go back to your main activity, you are just adding it to the stack. However, if you don't want to worry about popping everything off the stack, you can add this to your activity's manifest entry, and the system will place the main activity at the top of the stack and remove anything else that was on it.
This approach is a little cleaner than calling finish()
on all of your activities because you may want to go from activity 3 back to activity 2.
Answered By - Dan Harms
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.