I have two application, App A and App B, now I want to start an activity in App B from App A, the launchmode of this Activity is “singleTask”.
The order: Activity X (App A) ———> Activity Y (App B) ———> Activity Z (App B, launchMode=“singleTask”)
As default AndroidManifest config, there will be two App shown in the Task Manager, I hope users can only see App A label in Task Manager, so when they switch between tasks they don’t click App B. Before Android 11(Android R), I use the attribute taskAffinity as below to solve this problem.
Both Activity X and Activity Z, add this in AndroidManifet.xml
android:taskAffinity="com.abc.xxx”
So these activity can both house in one activity task. In Android 10, it works.
However, it doen’t work in Android11 anymore. And, I didn’t find any new features relevant to this scene.
How can I make ApplicationA’s activity task house the activity of ApplicationB which launchmode is singleTask? Let users see only one task(ApplicationA) in task manager.
You can't. And you shouldn't. The reason it was working before is that
taskAffinitywas trumping (overriding) thelaunchMode. Obviously they have changed/fixed that in Android 11.If an
Activityis declared assingleTaskthen this tells Android that theActivitywants to be the rootActivityin its own task. When you launch thisActivity, it should be launched in a new task, not into the same task as theActivitydoing the launching.In earlier versions of Android, the
Activitywould be launched into the same task if theActivityhad the sametaskAffinityas the rootActivityof the launching task. This was never clearly documented, and so it wasn't clear if this was a "bug" or a "feature". It looks like they have finally changed/fixed this in Android 11.See my answers to these related questions: