启动模式

2019-04-28  本文已影响0人  米豆同学

LaunchMode

1. standard

1:com.example.lzh_d.launchmodetest/.MainActivity

2:com.example.lzh_d.launchermodetest2/.MainActivity

3:com.example.lzh_d.launchermodetest2/.SecondActivity

1->2

1.2都是standard

    Running activities (most recent first):
      TaskRecord{af6f390 #3512 A=com.example.lzh_d.launchmodetest U=0 StackId=1 sz=2}
        Run #10: ActivityRecord{8ffb8bc u0 com.example.lzh_d.launchermodetest2/.MainActivity t3512}
        Run #9: ActivityRecord{6107fde u0 com.example.lzh_d.launchmodetest/.MainActivity t3512}
      TaskRecord{f5a8266 #3491 A=com.tencent.mm U=0 StackId=1 sz=1}
        Run #8: ActivityRecord{7a1cfe4 u0 com.tencent.mm/.ui.LauncherUI t3491}
      TaskRecord{fff18d2 #3509 A=com.example.lzh_d.launchermodetest2 U=0 StackId=1 sz=1}
        Run #7: ActivityRecord{2abdc4f u0 com.example.lzh_d.launchermodetest2/.MainActivity t3509}

2. singleTop

1>2,1是standard,2是singleTop,与standard相同

2->2

2已经位于栈顶没有被重新创建

    Running activities (most recent first):
      TaskRecord{ba16c5d #3522 A=com.example.lzh_d.launchermodetest2 U=0 StackId=1 sz=1}
        Run #2: ActivityRecord{e7c20de u0 com.example.lzh_d.launchermodetest2/.MainActivity t3522}
      TaskRecord{f3d9ce8 #3341 A=com.netease.newsreader.activity U=0 StackId=1 sz=1}
        Run #1: ActivityRecord{893c1a9 u0 com.netease.newsreader.activity/com.netease.nr.phone.main.MainActivity t3341}
      TaskRecord{8a730f7 #3180 A=com.android.incallui U=0 StackId=1 sz=1}
        Run #0: ActivityRecord{b389462 u0 com.android.incallui/.InCallScreen t3180}

对比standard

    Running activities (most recent first):
      TaskRecord{8249d5b #3520 A=com.example.lzh_d.launchermodetest2 U=0 StackId=1 sz=2}
        Run #2: ActivityRecord{2b9ad91 u0 com.example.lzh_d.launchermodetest2/.MainActivity t3520}
        Run #1: ActivityRecord{f40170f u0 com.example.lzh_d.launchermodetest2/.MainActivity t3520}
      TaskRecord{8a730f7 #3180 A=com.android.incallui U=0 StackId=1 sz=1}
        Run #0: ActivityRecord{b389462 u0 com.android.incallui/.InCallScreen t3180}

3. singleTask

1->2

1 standard,2 singleTask

    Running activities (most recent first):
      TaskRecord{c94e00b #3513 A=com.example.lzh_d.launchermodetest2 U=0 StackId=1 sz=1}
        Run #9: ActivityRecord{ffe3677 u0 com.example.lzh_d.launchermodetest2/.MainActivity t3513}
      TaskRecord{af6f390 #3512 A=com.example.lzh_d.launchmodetest U=0 StackId=1 sz=1}
        Run #8: ActivityRecord{6107fde u0 com.example.lzh_d.launchmodetest/.MainActivity t3512}
      TaskRecord{f5a8266 #3491 A=com.tencent.mm U=0 StackId=1 sz=1}
        Run #7: ActivityRecord{7a1cfe4 u0 com.tencent.mm/.ui.LauncherUI t3491}

1->2->3->2

1 standard,2 singleTask,3 standard

1启动2后,1和2分别位于栈A,栈B,2再启动3,3在栈B,3再启动2,3出栈,栈B中只有2.

    Running activities (most recent first):
      TaskRecord{c5fb4e7 #3535 A=com.example.lzh_d.launchermodetest2 U=0 StackId=1 sz=1}
        Run #3: ActivityRecord{c101916 u0 com.example.lzh_d.launchermodetest2/.MainActivity t3535}
      TaskRecord{8ea71d7 #3525 A=com.example.lzh_d.launchmodetest U=0 StackId=1 sz=1}
        Run #2: ActivityRecord{3ecef32 u0 com.example.lzh_d.launchmodetest/.MainActivity t3525}
      TaskRecord{f3d9ce8 #3341 A=com.netease.newsreader.activity U=0 StackId=1 sz=1}
        Run #1: ActivityRecord{893c1a9 u0 com.netease.newsreader.activity/com.netease.nr.phone.main.MainActivity t3341}
      TaskRecord{8a730f7 #3180 A=com.android.incallui U=0 StackId=1 sz=1}
        Run #0: ActivityRecord{b389462 u0 com.android.incallui/.InCallScreen t3180}

4. singleInstance

1->2

这种情况和singleTask一样

    Running activities (most recent first):
      TaskRecord{20c273e #3524 A=com.example.lzh_d.launchermodetest2 U=0 StackId=1 sz=1}
        Run #3: ActivityRecord{f624d33 u0 com.example.lzh_d.launchermodetest2/.MainActivity t3524}
      TaskRecord{8ea71d7 #3525 A=com.example.lzh_d.launchmodetest U=0 StackId=1 sz=1}
        Run #2: ActivityRecord{3ecef32 u0 com.example.lzh_d.launchmodetest/.MainActivity t3525}
      TaskRecord{f3d9ce8 #3341 A=com.netease.newsreader.activity U=0 StackId=1 sz=1}
        Run #1: ActivityRecord{893c1a9 u0 com.netease.newsreader.activity/com.netease.nr.phone.main.MainActivity t3341}
      TaskRecord{8a730f7 #3180 A=com.android.incallui U=0 StackId=1 sz=1}
        Run #0: ActivityRecord{b389462 u0 com.android.incallui/.InCallScreen t3180}

下面这种情况对比singleTask

1->2->3->2

1 standard,2 singleInstance,3 standard

1启动2后,1和2分别位于栈A,栈B,2再启动3,3在新建的栈C中,3再启动2,找到栈B中的2,此时栈A,B,C分别放着activity 1 ,2 ,3.

    Running activities (most recent first):
      TaskRecord{2e79031 #3532 A=com.example.lzh_d.launchermodetest2 U=0 StackId=1 sz=1}
        Run #4: ActivityRecord{9f8d08f u0 com.example.lzh_d.launchermodetest2/.MainActivity t3532}
      TaskRecord{16d8316 #3533 A=com.example.lzh_d.launchermodetest2 U=0 StackId=1 sz=1}
        Run #3: ActivityRecord{898ffc9 u0 com.example.lzh_d.launchermodetest2/.SecondActivity t3533}
      TaskRecord{8ea71d7 #3525 A=com.example.lzh_d.launchmodetest U=0 StackId=1 sz=1}
        Run #2: ActivityRecord{3ecef32 u0 com.example.lzh_d.launchmodetest/.MainActivity t3525}
      TaskRecord{f3d9ce8 #3341 A=com.netease.newsreader.activity U=0 StackId=1 sz=1}
        Run #1: ActivityRecord{893c1a9 u0 com.netease.newsreader.activity/com.netease.nr.phone.main.MainActivity t3341}
      TaskRecord{8a730f7 #3180 A=com.android.incallui U=0 StackId=1 sz=1}
        Run #0: ActivityRecord{b389462 u0 com.android.incallui/.InCallScreen t3180}

singleTask与singleInstance区别:singleInstance 独占一个栈,singleTask在栈中找到就置顶,并且其上activity出栈,可以和TaskAffinity联合使用,指定所在任务栈。

上一篇 下一篇

猜你喜欢

热点阅读