(A、B、C、D分别为Activity A、Activity B、Activity C、Activity D简写,
ActivitySingleTask为android:launchMode="singleTask"的Activity
ActivitySingleInstance为android:launchMode="singleInstance"的Activity)
1. standard:Activity的默认启动模式,
standard-demo0: 使用getApplicationContext()为Context时,会抛出异常.(修改StandModeTestcase.demo0(Context))
2. singleTop:
singleTop-demo0:
A: Intent.FLAG_ACTIVITY_SINGLE_TOP
B:
C:
ABCA->ABCA
singleTop-demo1:
A:
B:
C: Intent.FLAG_ACTIVITY_SINGLE_TOP
ABCC->ABC
3. singleTask:
singleTask-demo0:
A: Intent.FLAG_ACTIVITY_NEW_TASK
B:
C:
ABCA->ABC
singleTask-demo1:
A: Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
B:
C:
ABCA->A
onCreateA() onCreateB() onCreateC() onCreateA() onDestroyA() onDestroyB() onDestroyC()
singleTask-demo2:
ActivitySingleTask:
B:
C:
ActivitySingleTask B C ActivitySingleTask -> ActivitySingleTask
onCreateSingleTask() onCreateB() onCreateC() onNewIntentSingleTask() onDestroyB() onDestroyC()
4. singleInstance:
singleInstance-demo0:
ActivitySingleInstance:
B:
C:
ActivitySingleInstance B C ActivitySingleInstance -> B C ActivitySingleInstance
onCreateSingleInstance() onCreateB() onCreateC() onNewIntentSingleInstance()
参考代码:https://github.com/afunx/AndroidDemo365/tree/master/AndroidDemo365/ActivityLaunchMode