Android - Activity started in same task despite FLAG_ACTIVITY_NEW_TASK

    Android's documentation on FLAG_ACTIVITY_NEW_TASK is not clear in terms of the impact caused by taskAffinity. It just indicates that the desired activity would be started in a new task and user would be able to see multiple tasks from the recent tasks list.


However, this isn't always the case.

        Intent intent = new Intent();
        intent.setClass( this, TestActivity.class );
        intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
        startActivity( intent );

   The TestActivity is launched into the same task as that of the launching activity when both activities share the same task affinity. By default, all activities in an application share the same task affinity unless any of them have a different affinity set explicitly on them. In the latter case, TestActivity is indeed launched into its own task and users can see multiple tasks for the same application in the recent apps list.

        <activity
            android:name=".TestActivity"
            android:taskAffinity=".TestNewTask"
            android:label="@string/app_name" >
        </activity>

No comments: