androidandroid-activityandroid-homebuttonlaunchmode

LaunchMode & Recent App Principle


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:enter image description here

2nd:enter image description here

3rd:enter image description here

4th:enter image description here

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


Solution

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

    taskAffinity is needed, this works for me.