一、clearTaskOnLaunch:
clearTaskOnLaunch仅对根Activity有效
When the value is "true
", every timeusers start the task again, they are brought to its root activity regardless ofwhat they were last doing in the task and regardless of whether they used theBackorHome button to leave it. When the value is "false
", the task maybe cleared of activities in some situations (see thealwaysRetainTaskState attribute), but not always.
在AndroidManifest中,设置这个参数,当这个参数是true的时候,每次启动应用都会进入root activity 。不管之前是按back键的还是home键的。
二、用FLAG_ACTIVITY_CLEAR_TOP 实现清空Activity栈:
intent intent = new Intent(currentActivity,startActivity);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
startActivity的启动模式为默认的。
应用首次启动的是startActivity,而且在启动后不finish掉,跳转到其他的activity。
这种方式可以实现当前栈中startActivity上面的所有activity被清空。
系统原理:
假设启动顺序是:startActivity-->A-->B-->C-->