Why is secondary activity being destroyed when going back to main activity? [closed]

白昼怎懂夜的黑 提交于 2019-12-25 07:34:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!