Skip to content Skip to sidebar Skip to footer

Why Is Secondary Activity Being Destroyed When Going Back To Main Activity?

When going back to activity A (main activity) the activity B is being destroyed. Why is that happening? The example program I'm trying to understand is here: http://developer.andro

Solution 1:

Here's a representation of how each new activity in a task adds an item to the back stack. When the user presses the Back button, the current activity is destroyed and the previous activity resumes.

enter image description here

Why destroyed? Because the latest activity is on top of the stack and to get to the next activity, you pop the latest off (LIFO). More info here.

Solution 2:

Note: this occurs for activities from the same app. In short, when you're in an app and use "back" or "up" to go to your previous activity, the activity you were in is destroyed (the system automatically calls finish() on it).

Each different app has its own back stack, so if you're in Activity 1, go to Home, go to Launcher, and start a different app, you've started an "activity 2" but it's really not the same. The two activities are in different tasks.

Post a Comment for "Why Is Secondary Activity Being Destroyed When Going Back To Main Activity?"