Activity finish过程

    xiaoxiao2022-07-02  121

     

    MainActivity  启动 TestActivity,然后调用TestActivity的finish():

    I/System.out: MainActivity onResume I/System.out: TestActivity onCreate I/System.out: TestActivity onResume I/System.out: TestActivity finish TestActivity onPause I/System.out: java.lang.Throwable at com.champion.myapplication.TestActivity.onPause(TestActivity.java:34) at android.app.Activity.performPause(Activity.java:7071) at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1335) at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3941) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3918) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3892) at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3860) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1588) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6523) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) I/System.out: MainActivity onRestart I/System.out: MainActivity onResume I/System.out: TestActivity onStop I/System.out: java.lang.Throwable at com.champion.myapplication.TestActivity.onStop(TestActivity.java:40) at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1301) at android.app.Activity.performStop(Activity.java:7113) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4355) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4417) at android.app.ActivityThread.-wrap6(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1629) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6523) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) TestActivity onDestroy I/System.out: java.lang.Throwable at com.champion.myapplication.TestActivity.onDestroy(TestActivity.java:46) at android.app.Activity.performDestroy(Activity.java:7141) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1158) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4385) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4417) at android.app.ActivityThread.-wrap6(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1629) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6523) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)

    finish()切换Activity过程:TestActivty#finish()->AMS#finishActivity()->TestActivity$ApplicationThread#schedulePauseActivity()-AMS#activityPaused()->MainActivity$ApplicationThread#scheduleResumeActivity()->AMS#activityIdle()->TestActivity$ApplicationThread#scheduleDestroyActivity().

    其中scheduleDestroyActivity()会触发onPause,onStop,onDestroy。如果paused,则onPause不调用,如果stoped,则调用onDestroy即可。

    最新回复(0)