I have a problem in one of my apps when I start it from a notification. It never appears in the "recent app" list.
Without notifications, every thing works as expected: I start the app, navigate into and when I quit it (with home button or back button) after that I can go back into it with a long press on home button => ok.
The problem starts when I receive a notification. If I start the app from the notification, it starts the correct screen and I can use the app => ok. But when I quit the app (with home or back button) it do not appears anymore in the "recent app" list. More precisely:
- If the app was present in the "recent app" list before launching the app from the notification, it removes it
- If the app was not present in the "recent app" list, it does not add it
Below, my original code to add the notification in the status bar:
mNotification = new Notification(R.drawable.ic_notif, message, System.currentTimeMillis());
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(link));
notificationIntent.putExtra(...);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
mNotification.setLatestEventInfo(context, context.getString(R.string.app_name), message, contentIntent);
notificationManager.notify(ConfigApp.NOTIFICATION_ID, mNotification);
I tried adding a FLAG_ACTIVITY_NEW_TASK but it did not help:
Intent notificationIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(link));
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra(...);
Manifest declaration of the Activity started by the notification:
<activity
android:name=".activity.ActivityMessages"
android:label=""
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="hostapp"
android:pathPrefix="/prefixapp"
android:scheme="schemeapp" />
</intent-filter>
</activity>
Does anyone knows how to keep the app in the "recent app" list after being started form a notification?
Old topic but I discover solution (and I can't find in web anyone), maybe it will be helpful for sb. It doesn't give possibility to set any activity as a parent but I think (not sure) that you can change it programmatically (in OpenFromNotificationActivity) if it is necessary.
In manifest
Add the action
android.intent.action.MAIN
and the categoryandroid.intent.category.LAUNCHER
to the specification of your activity. Having two actions and categories seem like a hack but it's actually supported by Android.That should add it to the recent applications list. The reason is described in the Android developer documentation:
Try adding to the manifest the following:
Good luck, Luis
I bumped into same issue. The problem was that my activity had android:label="". When I open Activity from the Notification then it replaces root activity in the app task with current one. And Android excludes activities with empty label from Recents (see source code).
To hide title of activity you should use:
You need to use separate
Intent Filters
for each action/category pair: