问题
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.android.com/shareables/training/ActivityLifecycle.zip
回答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.
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.
回答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.
来源:https://stackoverflow.com/questions/17624187/why-is-secondary-activity-being-destroyed-when-going-back-to-main-activity