【发布时间】:2012-08-31 08:36:54
【问题描述】:
当我从通知启动某个应用时,我的其中一个应用出现问题。它永远不会出现在“最近的应用”列表中。
没有通知,一切都按预期工作:我启动应用程序,导航到当我退出它(使用主页按钮或返回按钮)之后,我可以通过长按主页按钮返回它 => 好的.
当我收到通知时,问题就开始了。如果我从通知启动应用程序,它会启动正确的屏幕,我可以使用应用程序 => 好的。但是当我退出应用程序(使用主页或返回按钮)时,它不再出现在“最近的应用程序”列表中。更准确地说:
- 如果在从通知中启动应用程序之前,该应用程序存在于“最近的应用程序”列表中,则会将其删除
- 如果该应用不在“最近使用的应用”列表中,则不会添加它
下面是我在状态栏中添加通知的原始代码:
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,但没有帮助:
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>
有谁知道如何在启动后通过通知将应用保留在“最近的应用”列表中?
【问题讨论】:
-
这发生在哪个安卓版本上?
-
如果删除
<category android:name="android.intent.category.DEFAULT" />会发生什么?另外,请尝试删除intent-filter组。 -
@WebnetMobile.com 自 2.2 以来的每个版本
-
@Eric 因为我使用隐式意图从通知中启动应用程序,所以我需要指定一个类别。如果我没有通知的隐式Pendingintent什么都不做(因为它找不到对应的Activity)
-
@ol_v_er 你解决了这个问题吗?谢谢
标签: android android-intent android-notifications