Android - onNewIntent is not called - singletop activities

天涯浪子 提交于 2019-12-11 12:17:41

问题


I have launcher A (activity A1) and application B (activities B1, B2 both singletop).

A1 -> B1 -> B2 -> A1 -> B2.

However onNewIntent wasn't called on activity B2, B2 did call direct onResume but not onNewIntent.

Launcher A : Activity A1:

Intent app_B = getPackageManager().getLaunchIntentForPackage(PACKAGE_B);
startActivity(app_B);

I want:

A1 -> B1 -> B2 -> A1 -> B2.onNewIntent(Intent intent)

But not:

A1 -> B1 -> B2 -> A1 -> B2.onResume() 

Can someone helps me out? Thanks. (Debug on Android 4.4.2)


回答1:


onNewIntent(Intent intent)

is only called once before the activity is created. After that It will not call untill you destroy and recreate the activity... Please see the docs, It will more clarify you, http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)




回答2:


For onNewIntent(Intent intent) to be called, you must declare your activity's launchmode in the manifest as android:launchMode="singleTop" OR android:launchMode="singleTask"

http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode



来源:https://stackoverflow.com/questions/32566331/android-onnewintent-is-not-called-singletop-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!