本文介绍了LaunchMode&安培;近期的应用原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WidgetResultActivity和NotificationResultActivity,我都设置了launchmode = singleInstance。但是他们有不同的行为:WidgetResultActivity将不会从近期开业,而NotificationResultActivity将始终从最近的(这是单独开不MainActivity!)打开。所以,我怎么能禁止从最近的,THX NotificationResultActivity开放。

 <活动
        机器人:名字=。WidgetResultActivity
        机器人:launchMode =singleInstance
        机器人:主题=@安卓风格/ Theme.Translucent.NoTitleBar/>    <活动
        机器人:NotificationResultActivityNAME =
        机器人:launchMode =singleInstance
        机器人:主题=@安卓风格/ Theme.Translucent.NoTitleBar/>

编辑:刚才看到我的ATester应用程序,当我从通知开...

测试code:

  NotificationManager经理=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    通知通知=新的通知(R.drawable.ic_launcher,的getString(R.string.app_name),java.lang.System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR;
    意向意图=新意图(这一点,ExcludeFromRecentActivity.class);
    // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    活动的PendingIntent = PendingIntent.getActivity(这一点,R.string.app_name,意向,PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(此,开放的活动:+ ABox.class.getSimpleName(),新意图(),活动);
    manager.notify(R.string.app_name,通知);

测试清单:

 <活动
        机器人:名字=。ATester1
        机器人:标签=@字符串/ APP_NAME>
    < /活性GT;
    <活动
        机器人:名字=。ATester2
        机器人:标签=@字符串/ APP_NAME>
    < /活性GT;
    <活动
        机器人:名字=。ATester3
        机器人:标签=@字符串/ APP_NAME>
    < /活性GT;
    <活动
        机器人:名字=。ExcludeFromRecentActivity
        机器人:excludeFromRecents =真
        机器人:标签=@字符串/ APP_NAME>
    < /活性GT;

测试图片:

1:

2日:

3:

4:

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


解决方案

 的android:taskAffinity =
机器人:excludeFromRecents =真
机器人:launchMode =singleInstance

需要taskAffinity,这对我的作品。

I have a WidgetResultActivity and a NotificationResultActivity, I set both their launchmode=singleInstance. But they have different behaviors: WidgetResultActivity will not opened from RECENT, while NotificationResultActivity will always be opened from RECENT(It is opened alone! Without MainActivity). So How can I forbid NotificationResultActivity opening from REcent, thx.

    <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" />

EDIT: Just See my ATester App, when I opened from notification...

Test code:

    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);

Test manifest:

    <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>

Test Images:

1st:

2nd:

3rd:

4th:

EDIT: What I really need is DIALOG BEHEVIOR LIKE ACTIVITY, I will ask in another post. @WebnetMobile.com, thank you all the same.

解决方案
android:taskAffinity=""
android:excludeFromRecents="true"
android:launchMode="singleInstance"

taskAffinity is needed, this works for me.

这篇关于LaunchMode&安培;近期的应用原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:17