Detailed explanation of Android activity stack and management examples

This example demonstrates how to change the order of existing activities in the current task stack by setting the flag of the intent object.

1. Description of activity startup tag of intent object:

This flag is usually not set in the application code, but is set by the system to the activity in single task startup mode.

If this flag is added to the intent object, any existing tasks associated with the activity will be cleared before the activity is started. In other words, the new activity will become the root of an empty task, and any other activity will be destroyed. It follows flag_ ACTIVITY_ NEW_ Task is used in combination.

If this flag is set for the intent object and the activity to be started is already running in the current task, instead of creating a new instance of the activity, turn off all other activities above the activity in the stack, and then send the new intent object to the existing activity (at this time, it is at the top of the stack).

If this flag is set for the intent object, when the task is reset, the activities after this flag point in the activity stack of the task should be cleared.

If this flag is set for the intent object, the new activity will not be kept in the list of recently started activities.

If this flag is set for the intent object, and the intent object is used to start a new activity from an existing activity, and then transfer the reply target of the existing activity to the new activity. The new activity obtained in this way can call the setresult (int) method to return the result to the original activity.

This flag is usually not set by the application code. If the activity is started from the history, the system will set this flag.

This tag is not used unless you implement your own top-level application launcher.

If this flag is set for the intent object, the activity will become the starting point of a new task on the history stack.

If this flag is set for the intent object, it will prevent the system from switching between activities.

If this flag is set for the intent object, the new activity will not be retained in the history stack.

If this flag is set for the intent object, it will prevent the callback of the normal onuserleavehint () method before the newly started activity to the foreground is suspended. If the phone dialing or alarm clock program needs to use this flag to start the activity.

If this flag is set for the intent object and the intent object is used to start a new activity from an existing activity, the activity cannot be used to accept the new intent object sent to the top-level activity. It is generally considered that the activity started with this flag will be terminated immediately by itself.

If this flag is set for the intent object, the existing activities in the task history stack will be brought to the foreground.

If this flag is set for the intent object, and the activity is started in a new task or brought to the top level in the existing task stack, it will be started as the front door of the task.

If this flag is set for the intent object, if the activity to be started is already running at the top of the history stack, the activity will not be started.

If this flag is set for the intent object, it will cause the newly started task to be placed on the current main activity task.

2. Example code

2.1. Definition manifest file (androidmanifest. XML)

2.2. Define string resources (strings. XML)

2.3. Define layout file

reorder_ on_ launch. xml

reorder_ two. xml

reorder_ three. xml

reorder_ four. xml

2.4. Create activity

ReorderOnLaunch. java

ReorderTwo. java

ReorderThree. java

ReorderFour. java

3. Activity stack management class

The above is a detailed explanation of the Android activity stack and management examples introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>