我有一个WidgetResultActivity和一个NotificationResultActivity,我设置了它们的launchmode = singleInstance。但是它们有不同的行为:WidgetResultActivity不会从RECENT打开,而NotificationResultActivity将始终从RECENT打开(它是独立打开的!没有MainActivity)。那么我该如何禁止从REcent,thx开放的NotificationResultActivity。LaunchMode&Recent App Principle
<activity
android:name=".WidgetResultActivity"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".NotificationResultActivity"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
编辑:刚才看到我的ATester应用程序,当我从通知开...
测试代码:
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, getString(R.string.app_name), java.lang.System.currentTimeMillis());
notification.flags = Notification.FLAG_NO_CLEAR;
Intent intent = new Intent(this, ExcludeFromRecentActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent activity = PendingIntent.getActivity(this, R.string.app_name, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(this, "Open Activity: " + ABox.class.getSimpleName(), "new Intent()", activity);
manager.notify(R.string.app_name, notification);
测试清单:
<activity
android:name=".ATester1"
android:label="@string/app_name" >
</activity>
<activity
android:name=".ATester2"
android:label="@string/app_name" >
</activity>
<activity
android:name=".ATester3"
android:label="@string/app_name" >
</activity>
<activity
android:name=".ExcludeFromRecentActivity"
android:excludeFromRecents="true"
android:label="@string/app_name" >
</activity>
测试图片:
1st:
第二:
3:
4:
编辑:我真正需要的是DIALOG BEHEVIOR LIKE活动,我会请在另一篇文章。 @ WebnetMobile.com,谢谢你们一样。
发生这种情况是因为AndroidManifest属性android:taskAffinity优先于FLAG_ACTIVITY_NEW_TASK。如果你想让ActivityB与ActivityA处于不同的任务,你需要给它一个不同的taskAffinity。 – user1269737