protected void onNewIntent(Intent
API level 1
This is called for activities that set launchMode to "singleTop" in their package, or if a client used the
FLAG_ACTIVITY_SINGLE_TOP
flag when calling
startActivity(Intent)
. In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.
An activity will always be paused before receiving a new intent, so you can count on
onResume()
being called after this method.
Note that
getIntent()
still returns the original Intent. You can use
setIntent(Intent)
to update it to this new Intent.
Parameters
intent | The new intent that was started for the activity. |
See Also
-
getIntent()
-
setIntent(Intent)
-
onResume()
調用 onNewIntent 有兩種情況:
第一種: 這個 Activity A設定為 SingleTop 啟動模式。也就是位于棧頂就不新建立。
第二種: 啟動一個 Activity A時把 Intent flag 設定為
FLAG_ACTIVITY_SINGLE_TOP
如果重新啟動這個 Activity A,當 A 位于棧頂時(這樣 A 不用建立執行個體),onNewIntent 将會被調用。
另外,如果有必要更新擷取的 Intent,需要調用下 setIntent。這個方法一般也是和 onNewIntent 連用的。