当前位置:网站首页>Activity startup mode and life cycle measurement results

Activity startup mode and life cycle measurement results

2022-06-23 05:53:00 Muzi 102

I am often asked by the interviewer during the interview activity Life cycle problems , However, we usually only have a brief understanding of the common , While the interviewer is always asking about the life cycle of exotic situations , So I wrote a demo, Carefully check the real situation and the results ( The most embarrassing thing is that the interviewer said , Go back and try )

 Picture description here

Activity Boot mode
standard: Create everything ( Default startup mode )
singleTop: Not on top target Activity,new One
singleTask: Not on top target Activity, remove target Above , Turn yourself into top.
singleInstance: Open up private task, Other completely independent of the program activity Of task.

standard Pattern

One 、 Under normal circumstances, start a activity, Its life cycle :(Activity_A Do a test )
1、 start-up ->back Key returns :
onCreat()->onStart()->onResume()->onPause()->onStop()->onDestroy()
 Picture description here
2、 start-up ->home desktop -> And on again app( Without being killed ):
onCreat()->onStart()->onResume()->onPause()->onStop()->onRestart()->onStart()->onResume()
 Picture description here

singleTop Pattern

One 、 Under normal circumstances, start a activity, Its life cycle :(Activity_B Do a test )
1、 start-up ->back Key returns : The result is the same as standard Pattern
2、 start-up ->home desktop -> And on again app( Without being killed ): The result is the same as standard Pattern
3、 Already on top , Start your situation again :
onCreat()->onStart()->onResume()->onPause()->onNewIntent()->onResume()->onPause()->onStop()->onDestroy()
 Picture description here
4. There are already... In the stack , But not at the top :
 Picture description here

singleTask Pattern

One 、 Under normal circumstances, start a activity, Its life cycle :(Activity_B Do a test )
1、 start-up ->back Key returns : The result is the same as standard Pattern
2、 start-up ->home desktop -> And on again app( Without being killed ): The result is the same as standard Pattern
3、 Already on top , Start your situation again : The result is the same as singleTop Pattern
4. There are already... In the stack , But not at the top :
 Picture description here

singleInstance Pattern

One 、 Under normal circumstances, start a activity, Its life cycle :(Activity_B Do a test )
1、 start-up ->back Key returns : The result is the same as standard Pattern
2、 start-up ->home desktop -> And on again app( Without being killed ): The result is the same as standard Pattern
3、 Already on top , Start your situation again : The result is the same as singleTop Pattern

4. There are already... In the stack , But not at the top : The result is the same as singleTask Pattern

Activity A start-up B Then return A A and B Life cycle changes of ( The order )

 Picture description here

原网站

版权声明
本文为[Muzi 102]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230414188714.html