Search code examples
androidandroid-activityactivity-lifecycleadk

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.android.com/shareables/training/ActivityLifecycle.zip


Solution

  • 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.