2012-10-23 72 views
1

我有一个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:enter image description here

第二:enter image description here

3:enter image description here

4:enter image description here

编辑:我真正需要的是DIALOG BEHEVIOR LIKE活动,我会请在另一篇文章。 @ WebnetMobile.com,谢谢你们一样。

回答

1
android:taskAffinity="" 
android:excludeFromRecents="true" 
android:launchMode="singleInstance" 

taskAffinity是需要的,这对我很有用。

+0

发生这种情况是因为AndroidManifest属性android:taskAffinity优先于FLAG_ACTIVITY_NEW_TASK。如果你想让ActivityB与ActivityA处于不同的任务,你需要给它一个不同的taskAffinity。 – user1269737

2

为了防止活动被添加到最近通话,加

android:excludeFromRecents="true" 

<activity>申报清单:android的文档android:excludeFromRecents

<activity 
    android:name=".NotificationResultActivity" 
    android:launchMode="singleInstance" 
    android:excludeFromRecents="true" 
    android:theme="@android:style/Theme.Translucent.NoTitleBar" /> 

见。

+0

感谢您的快速回复。我尝试过,但“excludeFromRecents”将从RECENT.Right中截取所有我的活动? – thecr0w

+0

不确定什么是“所有活动”?有活动或没有。没有一半的活动:)该标签将阻止'NotificationResultActivity'出现在最近。它不会影响其他活动 - 这些将会出现,除非您也将此属性添加到他们的''块中。 –

+0

它影响其他活动:在NotificationResultActivity打开后,我的应用在RECENTS中消失。 (用户不会很方便地从RECENT打开我的应用程序,希望你能明白我的意思) – thecr0w

相关问题