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

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top