Common activities FLAG

Source: Internet
Author: User

I have been familiar with tasks, affinity, and launch mode since I got started with Android. I 've been reading activities and tasks in the dev guide over the past few days. I just took some notes and sorted out this part of my knowledge.

One feature of Android is that the activity of application a can start the activity of application B, although a and B are irrelevant, in the user's opinion, the two scenarios are closely linked, both constitute a whole visually. Android defines this misunderstanding as a task. It is neither a class nor an element in androidmainifest. xml. In terms of performance, a task is like a stack. One activity is an element that forms a stack. It is simple and repetitive, such as push and pop-up.

The default rules always meet the requirements of most application scenarios, but some exceptions always break the conventional practice. The default rules of tasks are also not unbreakable, and there are still some modification methods. With the flags in intent and the attributes of the activity element in androidmainifest. XML, you can control the association and behavior of the activity in the task.

In Android. content. intent, a total of 20 different flags are defined, and there are four closely related tasks:

  1. Flag_activity_new_task
  2. Flag_activity_clear_top
  3. Flag_activity_reset_task_if_needed
  4. Flag_activity_single_top

When the four flags are used, one intent can set one flags or multiple flags can be selected for combination.

By default, a new activity is started through startactivity (). The new activity will be in the same stack as the caller. However, if the intent object passed to startactivity () contains flag_action_new_task, the situation will change.-The system will "Search" for a new activity for a task different from that of the caller. But must the task be new? If this is the first execution, this idea is true. If it is not, there is already a task containing this activity.
Otherwise, the activity will not be started.

If the flag is flag_activity_clear_top and the current task already has this activity, the situation will be different. Android not only does not start a new activity instance, but also ends all the activities on the activity in the task and sends the intent to the existing activity. After the activity receives the intent, it can perform the next step in onnewintent (), or it can end and recreate itself. If the activity
In androidmainifest. XML, set the startup mode to "standrd".-default mode. If flag_activity_single_top is not set in intent, the latter is selected. Otherwise, it selects the former. Flag_activity_clear_top can also be used with flag_action_new_task.

If flag_activity_single_top is set for the flag, it means that if the activity is already running on the top of the task, the activity will no longer be started.

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.