对于Android的Activity启动模式的一些总结和理解

安卓Activity的启动模式

1.1   两种启动方式

1.      在AndroidMainfest.xml中启动

例如:

AndroidMainfest.xml.xml中设置Activity的launchMode=“singleTop”

有singleInstance,singleTask,singleTop,standard四种可选

2.      在代码中启动

例如:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

重要的几个Intent Flag介绍:

l  FLAG_ACTIVITY_CLEAR_TOP

如果在ABCD的堆栈状态下,以该标识启动B,则会销毁CD,且B也是重新创建的(与SingleTask有区别),如果配合FLAG_ACTIVITY_SINGLE_TOP,则就会成为类似SingleTask的模式

l  FLAG_ACTIVITY_BROUGHT_TO_FRONT

如果ABCD中A以这个标识启动B,则D再启动B,B将会被调入前台,成为ACDB,且B不会重新创建

l  FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

这个标识主要用于创建一个还原点,再次启动该Task时会将还原点之上包括其本身都销毁掉,如果在一个程序中以该标识启动了另外一个程序的功能,如一个用于看图的软件,当退出桌面,再点击这个程序,看图软件会消失。

l  FLAG_ACTIVITY_NEW_TASK

这个是最常用的,但是往往会被误解,在程序根Activity的Task栈里加此标识开启新Activity都不会创建新的Task,只有当另一程序(进程)启动带有改标识的Activity时,才会创建新的Task。如果配合FLAG_ACTIVITY_NEW_MULTI_TASK,则无论什么情况都会创建新的Task,就成了SingleInstance的情况了。

3.      问题:代码设置的启动模式和AndroidMainfest.xml设置的启动模式冲突的时候,会按照哪个执行?

Intent Flag 会覆盖Manifest里面的launchMode

1.2   四种启动模式

1.    standard

默认模式,启动的所有Activity都会入栈,无论是之前启动过的还是没有启动过的,最终会形成的特色栈况为: ABCDEF…….或者ABCDDCEFAB……..

每次激活Activity时(startActivity),都创建Activity实例,并放入任务栈

2.    singleTop

跟标准模式唯一的区别就是,当栈顶为要启动的Activity时,复用该Activity,只会调用onNewIntent,而不会onCreate。所以不会出现ABCDD,而只会有ABCD,

3.    singleTask

 设置了"singleTask"启动模式的Activity,它在启动的时候,会先在系统中查找属性值affinity等于它的属性值taskAffinity的任务存在;如果存在这样的任务,它就会在这个任务中启动,否则就会在新任务中启动。因此,如果我们想要设置了"singleTask"启动模式的Activity在新的任务中启动,就要为它设置一个独立的taskAffinity属性值。

如果设置了"singleTask"启动模式的Activity不是在新的任务中启动时,它会在已有的任务中查看是否已经存在相应的Activity实例,如果存在,就会把位于这个Activity实例上面的Activity全部结束掉,即最终这个Activity实例会位于任务的堆栈顶端中。

看测试test 2.1 & 2.2

4.    singleInstance

启动的Activity会开启一个新的Task并独享,在其上启动的Activity会寻找其他合适的Task;如果应用1的任务栈中创建了MainActivity实例,如果应用2也要激活MainActivity,则不需要创建,两应用共享该Activity实例

 

1.3   调试分析的方法

1.      ActivityManager获取任务栈信息 :

必须在程序中注入调试代码,因为要控制在发布时代码必须被清理了。RunningTaskInfo虽然能够告诉我们有多少个Activity保存在其上,但是没有提供完整的列表,只能看到头尾两个Activity。给出的两个Activity的属性:topActivity和baseActivity也只是ComponentName类型,并非真实的Activity对象,因此除了类的名字没有其他更多信息。

2.      adb命令:

进入你的adb目录的platform-tools目录下,输入一下命令:

l  adb shell dumpsys activity     (包含了activity,service等)

出来的内容太多了现场演示了

l  adb shell dumpsys activity activities  出来的信息少一些,只和Activity相关,这里我使用了这个,方便查看

出来的内容太多了现场演示了,展示下面的一部分

例子:展示的某个Activity相关的内容:

* Hist #1: ActivityRecord{17aec5bb u0 com.tencent.mobileqq/.activity.QQLSActivity t20145}

          packageName=com.tencent.mobileqq processName=com.tencent.mobileqq

          launchedFromUid=10214 launchedFromPackage=com.tencent.mobileqq userId=0

          app=ProcessRecord{2b50d726 12735:com.tencent.mobileqq/u0a214}

          Intent { flg=0x14840000 cmp=com.tencent.mobileqq/.activity.QQLSActivity }

          frontOfTask=false task=TaskRecord{182ccc00 #20145 A=com.tencent.mobileqq U=0 sz=2}

          taskAffinity=com.tencent.mobileqq

          realActivity=com.tencent.mobileqq/.activity.QQLSActivity

          baseDir=/data/app/com.tencent.mobileqq-2/base.apk

          dataDir=/data/data/com.tencent.mobileqq

          stateNotNeeded=false componentSpecified=true mActivityType=0

          compat={480dpi} labelRes=0x7f0a12eb icon=0x7f020358 theme=0x103005f

          config={0 1.0 ?mcc?mnc zh_CN ldltr sw360dp w360dp h615dp 480dpi nrml long port finger -keyb/v/h -nav/h s.11}

          taskDescription: iconFilename=null label="null" color=ffe6e6e6

          launchFailed=false launchCount=0 lastLaunchTime=-1m10s530ms

          haveState=true icicle=Bundle[mParcelledData.dataSize=2664]

          state=STOPPED stopped=true delayedResume=false finishing=false

          keysPaused=false inHistory=true visible=true sleeping=true idle=true

          fullscreen=true noDisplay=false immersive=false launchMode=1

          frozenBeforeDestroy=false forceNewConfig=false

          mActivityType=APPLICATION_ACTIVITY_TYPE

          waitingVisible=false nowVisible=true lastVisibleTime=-1m10s6ms

          multiWindowStyle=MultiWindowStyle{type=0, zone=ZONE_UNKNOWN, option=0x01000002, bounds=null, isNull=false, isolatedCenterPoint=Point(0, 0), scale=0.0, specificTaskId=-1}

          bMultiInstance=false

          mIsLastShownWhenLocked=true

 

command + K是terminal的清屏快捷键

l  在adb命令中显示的launchMode代表的数值

standard : launchMode = 0

singleTop : launchMode=1  

singleTask: launchMode= 2 

singleInstance: launchMode=3 

l  Task概念:

Task相当于一个栈,用来管理Activity,默认情况下每一个程序都会拥有一个自己的Task,有自己独立的id,所以一个手机同时可能会拥有很多Task,标识就是id,默认情况下跟包名有关系。

1.4   启动模式对于获取到的Result的时机和内容的影响

StartActivityForResult的时候,requestCode必须>0,否则收不到result

startActivityForResultsingleInstance启动的对象的影响。LaunchMode与StartActivityForResult的关系
android5.0之前,Activity A通过startActivityForResult()启动一个Activity B,系统将首先检查Activity的launchMode,如果为A页面设置为SingleInstance或者B页面设置为singleTask或者singleInstance,则会在LaunchFlags中加入FLAG_ACTIVITY_NEW_TASK标志,而如果含有FLAG_ACTIVITY_NEW_TASK标志的话,onActivityResult将会立即接收到一个cancle的信息。所以会在启动Activity B时调用onActivityResult(),而返回Activity A时不会调用onActivityResult()。
android5.0之后,Activity A通过startActivityForResult()启动一个Activity B,不管A页面或者是B页面设置launchMode为任何一种模式,都是会在返回Activity A时调用onActivityResult()。

1.5   其他队启动模式有影响的参数

1.    android:allowTaskReparenting

默认false,程序A已经启动了数个Activity,其中包含Activity1,如果这个Activity1拥有该属性,当程序B也要启动它的时候,其可宿主到程序B内。看测试的例子test3.1 & 3.2

2.   清理Back stack

  如果用户离开一个task很久,系统就会清理这个task中的所有activities,除了根activity。当用户返回到这个task,只有根activity会被恢复。

  有一些activity的属性,你可以用来改变这一行为:

l  alwaysRetainTaskState

  默认false,操作系统会在程序长时间不会动的时候,清除Task状态,如果开启这个,系统会继续保持直到再次打开,只对根Activity生效

l  clearTaskOnLaunch

  默认false,如果开启,从桌面重新进入程序时,只会存在根Activity,如有其他程序的Activity,他们将会寻找宿主,这个属性也只对根生效

l  finishOnTaskLaunch

  默认false,如果开启,程序重新启动,会销毁所有存在的Activity,也只对根Activity生效

1.6   启动模式的适用场景

1.      singleTop: &  CLEAR_TOP

Notification的进入

2.      singleTask:

应用场景:应用主页面;

3.  SingleInstance:

系统手机的打电话程序之类的,

Widget

1.7   启动模式的原理分析

Activity启动和创建:http://www.cnblogs.com/bastard/archive/2012/04/07/2436262.html

Activity启动 

ActivityStack管理

源码地址:

http://grepcode.com/project/repository.grepcode.com/java/ext/com.google.android/android/

源码解析:

http://892848153.iteye.com/blog/1930416

ActivityStackSupervisor类解析:

http://www.aiuxian.com/article/p-1880233.html

 

SingleTask的疑惑:http://blog.csdn.net/luoshengyang/article/details/6714543


1.8   自己的一些测试

序号 测试模块 步骤 结果 结论
1.1 singleTask最为程序入口
1.MainActivity设置launchMode=singleTask,并且是程序入口Activity
2.正常启动BActivity(launchMode=standard),再正常启动CActivity(launchMode=standard)
3.从CActivity启动MainActivity(launchMode=singleTask)
2步骤之后:
Task id #20866
* Hist #2: ActivityRecord{298ecebf u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20866}
* Hist #1: ActivityRecord{27752bf5 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20866}
* Hist #0: ActivityRecord{24bf2e89 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20866}

3步骤之后:
Task id #20866
* Hist #0: ActivityRecord{24bf2e89 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20866}

 
1.2 singleTask不作为程序入口,不设置task affinity
1.MainActivity设置launchMode=singleTask,并且是程序入口Activity
2.启动BActivity(launchMode=singleTask),3.再启动BActivity(launchMode=singleTask)
4.再启动CActivity(launchMode=standard)
5.再启动BActivity(launchMode=singleTask)
6.再启动MainActivity(launchMode=singleTask)

步骤3之后:
Task id #21555
 * Hist #1: ActivityRecord{31dacb3e u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t21555}
 * Hist #0: ActivityRecord{14702289 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21555}
步骤4之后:
 Task id #21555
 * Hist #2: ActivityRecord{2ea9b777 u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t21555}
  * Hist #1: ActivityRecord{31dacb3e u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t21555}
  * Hist #0: ActivityRecord{14702289 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21555}
步骤5之后:
Task id #21552
* Hist #1: ActivityRecord{3ffd7da4 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t21552}
* Hist #0: ActivityRecord{99703cb u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21552}
步骤6之后:
Task id #21556
 * Hist #0: ActivityRecord{1a2ef18d u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21556}

 
1.3  
1.打开App B的BMainActivity
2.再打开App B的BSecondActivity(launchMode=singleTask)
3.按Home,打开App A的MainActivity
4.再打开App A的BActivity
5.再通过App A的BActivity打开App B的BSecondActivity(launchMode=singleTask)
步骤5之后:
Task id #25558
 * Hist #1: ActivityRecord{3e867083 u0 com.example.yanruzhang.bapplication/.BSecondActivity t25558}
* Hist #0: ActivityRecord{2265dfc u0 com.example.yanruzhang.bapplication/.BMainActivity t25558}
Task id #25559
* Hist #1: ActivityRecord{3f3e6c63 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t25559}
* Hist #0: ActivityRecord{30208a5c u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t25559}
 
2.1 singleTask不设置taskAffinity
1.MainActivity设置launchMode=singleTask,并且是程序入口Activity
2.正常启动BActivity(launchMode=standard),再正常启动CActivity(launchMode=standard)
3.从CActivity启动DActivity(launchMode=singleTask,不设置taskAffinity)
2步骤之后和序号1的2步骤之后相同
3步骤之后:
Task id #20870
 * Hist #3: ActivityRecord{20c57415 u0 com.example.yanruzhang.launchmodetestdemo/.DActivity t20870}
 * Hist #2: ActivityRecord{173c4b4b u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20870}
 * Hist #1: ActivityRecord{136f0f0d u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20870}
* Hist #0: ActivityRecord{3f514ce u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20870}

2.2 singleTask设置taskAffinity
1.MainActivity设置launchMode=singleTask,并且是程序入口Activity
2.正常启动BActivity(launchMode=standard),再正常启动CActivity(launchMode=standard)
3.从CActivity启动DActivity(launchMode=singleTask,taskAffinity=“com.zyr")
2步骤之后和序号1的2步骤之后相同
3步骤之后:
Task id #20876
* Hist #0: ActivityRecord{fda3e82 u0 com.example.yanruzhang.launchmodetestdemo/.DActivity t20876}
 Task id #20875
 * Hist #2: ActivityRecord{168a141e u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20875}
* Hist #1: ActivityRecord{11394488 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20875}
  * Hist #0: ActivityRecord{35df624d u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20875}
 
3.1 allowTaskReParenting
关于设置allowTaskReParenting=false
1.打开AApplication,默认启动AMainActivity界面
2.再打开BApplication的CommonActivity(launchMode=standard,allowTaskReparenting=false)页面
3.按home键
4.打开BApplication
5.按home键
6.打开AApplication
2步骤之后:
 Task id #21451
 * Hist #1: ActivityRecord{3f07fec5 u0 com.example.yanruzhang.bapplication/.CommonActivity t21451}
* Hist #0: ActivityRecord{30483d0c u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21451}
3步骤之后:和2一样
4步骤之后:
 Task id #21453
 * Hist #0: ActivityRecord{3eb809e8 u0 com.example.yanruzhang.bapplication/.BMainActivity t21453}
 Task id #21451
 * Hist #1: ActivityRecord{3f07fec5 u0 com.example.yanruzhang.bapplication/.CommonActivity t21451}
 * Hist #0: ActivityRecord{30483d0c u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21451}

 
3.2 allowTaskReParenting
关于设置allowTaskReParenting=true
1.打开AApplication,默认启动AMainActivity界面
2.再打开BApplication的CommonActivity(launchMode=standard,allowTaskReparenting=true)页面
3.按home键
4.打开BApplication
5.按home键
6.打开AApplication
2步骤之后:
 Task id #21458
  * Hist #1: ActivityRecord{3630e58b u0 com.example.yanruzhang.bapplication/.CommonActivity t21458}
  * Hist #0: ActivityRecord{3a4e9f38 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21458}
3步骤之后同2
4步骤之后:
 Task id #21459
 * Hist #1: ActivityRecord{3630e58b u0 com.example.yanruzhang.bapplication/.CommonActivity t21459}
 * Hist #0: ActivityRecord{2c091f5b u0 com.example.yanruzhang.bapplication/.BMainActivity t21459}
 Task id #21458
  * Hist #0: ActivityRecord{3a4e9f38 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21458}
 
4.1 singleTop
1.MainActivity设置launchMode=singleTask,并且是程序入口Activity
2.正常启动BActivity(launchMode=standard),再正常启动CActivity(launchMode=standard)
3.从CActivity启动CActivity(launchMode=standard)
 Task id #20894
* Hist #3: ActivityRecord{3cbfdf58 u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20894}
 * Hist #2: ActivityRecord{3ef91c28 u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20894}
* Hist #1: ActivityRecord{145eb9c2 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20894}
 * Hist #0: ActivityRecord{211fb9d u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20894}

4.2 singleTop
1.MainActivity设置launchMode=singleTask,并且是程序入口Activity
2.正常启动BActivity(launchMode=standard),再正常启动CActivity(launchMode=singleTop)
3.从CActivity启动CActivity(launchMode=singleTop)
4.点击返回键
步骤2之后:
Task id #20899
 * Hist #2: ActivityRecord{238cd0e2 u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20899}
 * Hist #1: ActivityRecord{248db264 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20899}
 * Hist #0: ActivityRecord{16549521 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20899}
步骤3之后:
Task id #20895
 * Hist #2: ActivityRecord{3713f571 u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20895}
* Hist #1: ActivityRecord{1bc44ac9 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20895}
 * Hist #0: ActivityRecord{36c4db0e u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20895}
步骤4之后:
 Task id #20899
 * Hist #1: ActivityRecord{248db264 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20899}
 * Hist #0: ActivityRecord{16549521 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20899}
 
5.1 singleInstance打开已经启动的应用的activity
1.MainActivity设置launchMode=singleTask,并且是程序入口Activity
2.正常启动BActivity(launchMode=standard)
3.再启动CActivity(launchMode=singleInstance)
4.从CActivity再启动CActivity(launchMode=singleInstance)
5.CActivity再启动DActivity(launchMode=standard)
6.点击返回键
7.点击返回键
8.点击返回键

步骤3之后:
Task id #20942
 * Hist #0: ActivityRecord{2b7d1cb7 u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20942}
 Task id #20939
  * Hist #1: ActivityRecord{353d6560 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20939}
 * Hist #0: ActivityRecord{20d65c47 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20939}

步骤4之后:
 Task id #20942
 * Hist #0: ActivityRecord{2b7d1cb7 u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20942}
  Task id #20939
  * Hist #1: ActivityRecord{353d6560 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20939}
 * Hist #0: ActivityRecord{20d65c47 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20939}

步骤5之后:
 Task id #20945
  * Hist #2: ActivityRecord{3ddd7b91 u0 com.example.yanruzhang.launchmodetestdemo/.DActivity t20945}
 * Hist #1: ActivityRecord{2c867758 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20945}
 * Hist #0: ActivityRecord{4136f95 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20945}
 Task id #20947
  * Hist #0: ActivityRecord{a42a56e u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20947}

步骤6之后:
返回到了BActivity
 Task id #20945
 * Hist #1: ActivityRecord{2c867758 u0 com.example.yanruzhang.launchmodetestdemo/.BActivity t20945}
 * Hist #0: ActivityRecord{4136f95 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t20945}
Task id #20947
  * Hist #0: ActivityRecord{a42a56e u0 com.example.yanruzhang.launchmodetestdemo/.CActivity t20947}

步骤7之后:
返回到了MainActivity
步骤8之后:
返回到了CActivity

 
6.1 standard模式打开别处应用的activity
1.从BApplication启动BMainActivity(launchMode = singleTask)
2.从 BMainActivity启动BSecondActivity(launchMode=standard)
3.按Home键回到桌面
4.打开AApplication的AMainActivity(launchMode = singleTask)
5.从AMainActivity打开BApplication的BSecondActivity
6.按回退键
5步骤之后:
 Task id #21476
 * Hist #1: ActivityRecord{12110283 u0 com.example.yanruzhang.bapplication/.BSecondActivity t21476}
 * Hist #0: ActivityRecord{1adf6ed0 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21476}
  Task id #21475
 * Hist #1: ActivityRecord{358cd107 u0 com.example.yanruzhang.bapplication/.BSecondActivity t21475}
  * Hist #0: ActivityRecord{33f1e004 u0 com.example.yanruzhang.bapplication/.BMainActivity t21475}
6步骤之后:
Task id #21476
 * Hist #0: ActivityRecord{1adf6ed0 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21476}
  Task id #21475
  * Hist #1: ActivityRecord{358cd107 u0 com.example.yanruzhang.bapplication/.BSecondActivity t21475}
 * Hist #0: ActivityRecord{33f1e004 u0 com.example.yanruzhang.bapplication/.BMainActivity t21475}

6.2 singleTask模式打开别处应用的activity
1.从BApplication启动BMainActivity(launchMode = singleTask)
2.从 BMainActivity启动BSecondActivity(launchMode=standard)
3.按Home键回到桌面
4.打开AApplication的AMainActivity(launchMode = singleTask)
5.从AMainActivity打开BApplication的BSecondActivity(launchMode = singleTask)
6.按回退键
步骤5之后:
Task id #21480
 * Hist #2: ActivityRecord{2237549b u0 com.example.yanruzhang.bapplication/.BSecondActivity t21480}
 * Hist #1: ActivityRecord{1c23859f u0 com.example.yanruzhang.bapplication/.BSecondActivity t21480}
* Hist #0: ActivityRecord{3eb92a8e u0 com.example.yanruzhang.bapplication/.BMainActivity t21480}
 Task id #21481
   * Hist #0: ActivityRecord{1b29b508 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21481}
步骤6之后:
 Task id #21480
  * Hist #1: ActivityRecord{1c23859f u0 com.example.yanruzhang.bapplication/.BSecondActivity t21480}
 * Hist #0: ActivityRecord{3eb92a8e u0 com.example.yanruzhang.bapplication/.BMainActivity t21480}
  Task id #21481
  * Hist #0: ActivityRecord{1b29b508 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21481}
 
6.3 singleTask模式带task Affinity打开别处应用的activity
1.从BApplication启动BMainActivity(launchMode = singleTask)
2.从 BMainActivity启动BSecondActivity(launchMode=standard)
3.按Home键回到桌面
4.打开AApplication的AMainActivity(launchMode = singleTask)
5.从AMainActivity打开BApplication的BSecondActivity(launchMode = singleTask,taskAfinity=“application A的包名")
6.按回退键
步骤5之后:
Task id #21486
  * Hist #1: ActivityRecord{32e36ce1 u0 com.example.yanruzhang.bapplication/.BSecondActivity t21486}
  * Hist #0: ActivityRecord{14874571 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21486}
 Task id #21485
 * Hist #1: ActivityRecord{1ce81a85 u0 com.example.yanruzhang.bapplication/.BSecondActivity t21485}
 * Hist #0: ActivityRecord{2ce4f92a u0 com.example.yanruzhang.bapplication/.BMainActivity t21485}
步骤6之后:
Task id #21486
 * Hist #0: ActivityRecord{14874571 u0 com.example.yanruzhang.launchmodetestdemo/.MainActivity t21486}
Task id #21485
 * Hist #1: ActivityRecord{1ce81a85 u0 com.example.yanruzhang.bapplication/.BSecondActivity t21485}
 * Hist #0: ActivityRecord{2ce4f92a u0 com.example.yanruzhang.bapplication/.BMainActivity t21485}

 

 

 

 

BY 张燕茹

你可能感兴趣的:(android,android基础)