eXistenZ
eXistenZ

Reputation: 336

onNewIntent() not being called when there is another activity on top

Seems that onNewIntent() of my MainActivity is not being called when I have another Activity on top of it, if I close the second Activity it does get called just fine, it's like the other Activity which is on top is blocking the messages? Both Activitys are set to singleTop in the manifest and I set the Intent from a notification:

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Does anybody know what could be wrong?

Thanks!

Upvotes: 2

Views: 2840

Answers (2)

marcinj
marcinj

Reputation: 49986

You have probably already searched google - there are lots of questions on why onNewIntent is not called.

It might depend on which android version you are doing tests, but you might try adding Intent.FLAG_ACTIVITY_SINGLE_TOP flag to your intent - even though you have it in your manifest, together with Intent.FLAG_ACTIVITY_CLEAR_TOP.

intent.setFlag(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);

this will remove activities above you activity which you want to launch.

But if your intent is to keep two activities alive, and switch between them, then look into android:taskAffinity and FLAG_ACTIVITY_NEW_TASK.

Upvotes: 2

Diego Torres Milano
Diego Torres Milano

Reputation: 69218

Verify that the correct launch mode is set for the Activity receiving the Intent. Set launchMode to "singleTop" in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent).

Upvotes: 1

Related Questions