Android task and back stack details 4: The Startup Mode defined in intent

Source: Internet
Author: User

Next, let's take an example of the rollback Stack:


The android browser app declares that the Webpage Browsing activity must be opened in its own task-by specifying the singletask Startup Mode in the <activity> element. this indicates that if your app sends an intent to open the android browser, its activity will not be placed in the task where your app is located. instead, a new task may be started by a browser, or if the browser is already running in the background, the task where it is located will be obtained to the foreground and accept the intent.

Whether an activity is started from a new task or in a task that already exists, the backend key always reverts to the previous activity. however, If you enable an activity declared as singletask mode in Task A, this activity may already have an instance of a task (Task B) in the background. task B was taken to the front desk and processed the new intent. at this time, the back key will first return the task bactivity layer by layer, and then return to the activity at the top of task. figure
4. demonstrate this situation.


Figure4.Demonstrate"Singletask"Startup ModeAcitvityHow to add to a back stack. IfActivityAlready a background task(TaskB)Part of your stack, the entire back stack is obtained to the front end, located in the current task
(TaskA)Above.


Note: The behaviors of actvitiy specified by the launchmode attribute can be overwritten by the flag of intent.

Use intentflags

When starting an activity, you can include a flag in the intent of startactivity () to change the default association between the activity and the task. The following flags can be used to change the default behavior:

  • Flag_activity_new_task

    Start activity in a new task-that is, it is not started in this task. if a task containing this activity is already running, the task will be taken to the foreground and Its UI status will be restored. Then the existing activity will receive new intent in onnewintent.

    This flag generates the same behavior as "singletask.

  • Flag_activity_single_top

    If the started activity is the current activity (at the top of the back stack), the existing instance receives the onnewintent () call instead of creating a new instance.

    This produces the same behavior as the "singletop" mode.

  • Flag_activity_clear_top

    If the activity to be started is already running in the current task, all other activities on it will be destroyed, and the activity will be restored, and the onnewintent (), initent is sent to this activity (now at the top)

    No launchmode attribute value corresponds to this behavior.

    Flag_activity_clear_top is usually used with flag_activity_new_task. when used together, an existing activity instance will be searched for in other tasks and placed in a position that can respond to intent.

    Note: If the Startup Mode of the activity is "standard", flag_activity_clear_top will cause the existing activity to be removed from the stack and then create a new instance at this location to process the arrival intent. this is because the "standard" mode will always create new instances for the new intent.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.