Android - onNewIntent is not called - singletop ac

2019-08-10 00:12发布

问题:

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