“This is the third day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021.”

SingleTask vs. singleInstance: After being launched, when the user presses the Back button, singleTask will roll back in its APP, while singleInstance will directly return to the original APP. If the user later opens the Activity APP from the desktop, singleTask will see the Activity at the top of the stack. SingleInstance will see that the Activity has disappeared and gone to the background, and when it starts up again, it will come to the foreground and call the onNewIntent() callback. Tasks seen in the most recent Task may not still exist, and tasks not seen in the most recent Task may not be destroyed (singleInstance)

In Android, only one Task per APP can be displayed in the latest Task list. However, it is taskAffinity that is used to identify this uniqueness. In the AndroidManifest file, this attribute acts as a pre-group for each Activity. Its default value is taken from the taskAffinity of the Application where the Activity resides. The taskAffinity of the Application is taken from the APP package name by default. Each Task also has its taskAffinity, which is taken from the Activity’s taskAffinity at the bottom of the stack. TaskAffinity can be customized using the androidmanifest.xml file. By default, the taskAffinity of all tasks in an APP is the same as the package name of the APP. For example, when we start a new Task, for example, when we open an APP for the first time after startup, The Task gets a taskAffinity, which is the value of the taskAffinity of the first Activity it started. The taskAffinity is ignored when we continue to open a new Activity from an already opened Activity. If the new Activity is configured with “singleTask”, Android will check to see if the taskAffinity of the new Activity is the same as that of the current Task. If it is, the new Activity will continue to be pushed. If it is different, The Activity finds the same Task as its taskAffinity and either pushes it or creates a new Task.

TaskAffinity and Recent Task List: Recent Task lists list existing tasks, but their taskAffinity needs to be different. In Android, the same taskAffinity can be created for multiple tasks, but only one of them can be displayed in the recent Task list