android 中activity的启动模式是singleTask时清除activity的栈顶activity的生命周期小计

安卓开发中经常会涉及到activity启动模式,当一个activity第singleTASK时 ,清除栈顶的activity的时候,位于栈顶的activity的生命周期是如何走完的呢?这里做一个小计:


BaseActivity的 启动模式是singleTask模式

   StandOneActivity

   StandTwoActivity

   StandThreeActivity 这三个activity的启动模式都是标准模式,


 启动的循序是 BaseActivity ->StandOneActivity->StandTwoActivity->StandThreeActivity

 生命周期如下:

 BaseActivity.onCreate()

                            onStart()

                                  onResume()

                                     onPuase()

                                         StandOneActivity.onCreate()

                                                                          onStart()

                                                                             onResume()

                                                                                onPause()

                                                                                   StandTwoActivity.onCreate()

                                                                                                                    onStart()

                                                                                                                        onResume()

                                                                                                                            onPause()

                                                                                                                               StandThreeActivity.onCreate()

                                                                                                                                                                   onStart()

                                                                                                                                                                      onResume()

                                                                                                                                                                          --------------这里回到BaseActivity上

                                       StandOneActivity.onStop()

                                                                        onDestaory()

                                                                                 StandTwoActivity.onStop()

                                                                                                               onDestory()

                                                                                                                               StandThreeActivity.onPause()

                                                                                                                                                                    BaseActivity.onResume()

                                                                                                                                                                                              StandThreeActivity.onStop()

                                                                                                                                                                                                                                    onDestory()


总的来讲,如果一个Activity的启动模式是SinleTask,在销毁栈内的其他Activity时 是从其栈顶的底部开始 一个一个的销毁,直到栈顶的activity 走onPause(),然后启动SingleTask的Activity,最后才销毁栈顶的Activity,走onStop及onDestaory      

你可能感兴趣的:(Android)