FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS doesn't work in KitKat and above

My Activity A opens Activity B in another task.
I am trying to have only one task icon in the taskbar / recent applications.
Activity B starts with the following flags: Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK
On OS versions <4.4 it works and only one task is shown in the taskbar.
In OS> = KitKat, you will see two icons in the applications that are in the image.

Sample code

    Intent activityBIntent;
    activityBIntent = new Intent(this, ActivityB.class);
    activityBIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(activityBIntent);
    finish();

      

ActivityB has a different affinity than ActivityA :

    <activity
        android:name="com.bla.ActivityB"
        android:launchMode="singleTop"
        android:taskAffinity=""
        android:theme="@style/AppTheme.NoActionBar">
    </activity>

<activity
    android:name="com.bla.ActivityA"
    android:launchMode="singleTop"
    android:theme="@style/AppTheme.NoActionBar"
    android:windowSoftInputMode="adjustResize" >
</activity>

      

Any idea what might be causing this? Any other workaround?

+3


source to share





All Articles