Android puts all started activities in the same stack as the previous one for management. For most applicationsProgramThis method works well, and you don't have to worry about how the activity is associated with the task or how they exist in the rollback stack. However, you may decide to break this common behavior. Maybe you want an activity in the application to start a new task (rather than in the current task) at startup, or when you start an activity, you want to use an existing instance (instead of creating a new instance at the top of the rollback stack), or you want to clear all activities other than the root activity in the rollback stack when the user leaves this task.
You can use the attributes in the <activity> list element and the identifier in the intent passed to the startactivity () method to do these tasks, or even more.
The main attributes of <activity> include:
Taskaffinity
Launchmode
Allowtaskreparenting
Cleartaskonlaunch
Alwaysretaintaskstate
Finishontasklaunch
Intent's main identifiers include:
Flag_activity_new_task
Flag_activity_clear_top
Flag_activity_single_top
In subsequent sections, you will see how to use these listing attributes and intent identifiers to define how an activity is associated with a task and its behavior in the rollback stack.
Warning:Most applications should not use the default behavior of terminal activity and task. If you decide that you must edit the default activity behavior, you must exercise caution and ensure the availability of the activity during startup and when you use the rollback button to return results from other activities and tasks. Make sure that the navigation result is consistent with the user's expected behavior.