launchMode爲singleTask,singleTop的時候,通過Intent啓到一個Activity,如果系統已經存在一個實例,系統就會將請求發送到這個實例上,但這個時候,系統就不會再調用通常情況下我們處理請求數據的onCreate方法,而是調用onNewIntent方法,如下所示:
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);//must store the new intent unless getIntent() will return the old one
processExtraData();
}
如果不調用setIntent(intent)方法,那麼當使用getIntent()方法時獲取到的就是原先舊的intent。
如果single task Activity處於任務棧的頂端,也就是說之前打開過的Activity,現在處於onPause、onStop狀態的話,其他應用再發送Intent的話,執行順序爲:
onNewIntent,onRestart,onStart,onResume。
注意順序,onResume還是會被調用的。