Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED 参数详解
/**
* If set, and this activity is either being started in a new task or
* bringing to the top an existing task, then it will be launched as
* the front door of the task. This will result in the application of
* any affinities needed to have that task in the proper state (either
* moving activities to or from it), or simply resetting that task to
* its initial state if needed.
*/
public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 0x00200000;
翻译:如果设置了该参数,activity从新的任务栈启动或者是从已经存在的任务栈中推到栈顶,activity都将作为栈顶界面显示,这将导致应用的所有栈都回到正常状态。或者直接重置该任务栈为初始状态。
一般用于启动activity时使用,通常和 FLAG_ACTIVITY_NEW_TASK 搭配使用。
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
FLAG_ACTIVITY_NEW_TASK
如果设置该参数,这个Activity会成为历史stack中一个新Task的开始。一个Task(从启动它的Activity到下一个Task中的 Activity)定义了用户可以迁移的Activity原子组。Task可以移动到前台和后台;在某个特定Task中的所有Activity总是保持相同的次序。
这个标志一般用于呈现“启动”类型的行为:它们提供用户一系列可以单独完成的事情,与启动它们的Activity完全无关。
使用这个标志,如果正在启动的Activity的Task已经在运行的话,那么,新的Activity将不会启动;代替的,当前Task会简单的移入前台。参考FLAG_ACTIVITY_MULTIPLE_TASK标志,可以禁用这一行为。
这个标志不能用于调用方对已经启动的Activity请求结果。