Activity Task and intent filter flag

Source: Internet
Author: User

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.

InAndroid. content. IntentA 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 defaultStartactivity ()Start a new activity. The new activity will be in the same stack as the caller. However, ifStartactivity ()The intent object containsFlag_action_new_task, The situation will change,-the system will be new
Activity "looks for" a task different from the caller. But must the task be new? If this is the first execution, this idea is true. If it is not, that is, a task containing the activity already exists, the activity will not be started.

If flag isFlag_activity_clear_topAt the same time, the current task already has this activity, so 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 canOnnewintent ()To do the next step, you can also end and recreate yourself. If
Activity sets the Startup Mode in androidmainifest. XMLMultiple-Default mode, and intent is not setFlag_activity_single_topThen it selects the latter. Otherwise, it selects the former.Flag_activity_clear_topYou can alsoFlag_action_new_taskIn combination.

If flag is setFlag_activity_single_topIf the activity is already running on top of the task, the activity will not be started again.

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.