当我从通知启动其中一个应用程序时,我遇到了问题。它永远不会出现在“最近使用的应用程序”列表中。
如果没有通知,一切都会按预期进行:我启动应用程序,导航到并退出它(使用主页按钮或后退按钮),之后我可以长按主页按钮返回到它=>确定。
当我收到通知时问题就开始了。如果我从通知启动应用程序,它会启动正确的屏幕,我可以使用该应用程序=>确定。但是,当我退出应用程序(使用主页或后退按钮)时,它不再出现在“最近的应用程序”列表中。更确切地说:
- 如果在从通知启动应用程序之前该应用程序存在于“最近的应用程序”列表中,则会将其删除
- 如果该应用程序不存在于“最近的应用程序”列表中,则不会添加它
下面是我在状态栏中添加通知的原始代码:
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);
我尝试添加一个FLAG_ACTIVITY_NEW_TASK http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK但这没有帮助:
Intent notificationIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(link));
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra(...);
由通知启动的 Activity 的清单声明:
<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>
有谁知道如何在通知启动后将应用程序保留在“最近的应用程序”列表中?