Activity side-by-side lifecycle

别说谁变了你拦得住时间么 提交于 2019-11-26 21:34:58

问题


Imagine that I have an Activity A and I'm starting a new activity B from that one.

What will be the Activities lifecycle side-by-side?

 1. A: onCreate 
 2. A: onStart 
 3. A: onResume

on A => startActivity(B)

 4. B: onCreate
 5. B: onStart

 6. A: onPause

 7. B: onResume

 8. A: onStop

Is this correct?


回答1:


Almost correct, just a minor difference. first A.onPause() and then B.onCreate()... etc

A: onCreate
A: onStart
A: onResume

on A => startActivity(B)

A: onPause
B: onCreate
B: onStart
B: onResume
A: onStop

Check this link for complete details

http://developer.android.com/guide/topics/fundamentals/activities.html#CoordinatingActivities




回答2:


There is a beautiful app in the developer's site which shows the activity lifecycle, pls have a look at it.You can download the app's source code here. Thought it might help someone :).



来源:https://stackoverflow.com/questions/10094131/activity-side-by-side-lifecycle

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