Functions and composition of intent objects

Source: Internet
Author: User
Document directory
  • Action item
  • Data item
  • Type
  • CATEGORY item
  • Component item
  • Extras item
  • Flags
Functions and composition of intent objects

In Android, the intent object is used to establish a connection and implement component communication. This is the intent mechanism in Android.

In the intent mechanism, Component Management Service is used to manage connected components. Component Management Service understands the functions and categories of components through component configuration information, this helps call components to find implementation components that meet requirements. Call components and implement components to completely decouple intent objects. Intent objects are the information carriers of Inter-component connections, the Component Management Service serializes the intent object passed by the calling component to the implementation component. The intent object can set some data items to describe its intent, the Component Management Service searches for matching implementation components based on these data items and constructs an implementation component intent object. The parsing action item is used to express the action to be executed by intent. You can use intent. setaction to set, intent. getaction. The action items follow the Java package naming rules, such as COM. sample. action. action_eat, of course, this is not necessary. Android has many defined actions, such as intent, which we often use. action_viewdata the action item defines "do", and the data item defines what to do. For example, when we need to browse an image by using the image browser component, we need to put the image address information in the data item, you can use intent. setdata to set, intent. getdata. The data format of the data item must comply with the URI standard type item. The data item definition must be "what ", the type item defines the "category" information for "do". For example, if you want to call the video playback component to play a video, the action item is intent. action_view: The data item is a URI (video address). If you only have this information, you may call the image browser component to play the video. This is obviously not acceptable, in this case, we can set the type item to indicate that I need a component that can play the video type. Because data items and type items are mutually exclusive, setting one item alone does not work. In this case, we can use intent. setdataandtype to set a category item we may need to do one thing on the basis of a certain condition. The category item describes the intent constraint, intent. addcategory. You can set multiple category items. That is to say, you must meet the conditions before doing this. We often need to start another application from one application. If we want to start another application from another entry program, we need to add the intent. category_launcher constraint. Component item when we do not need to set action, Data, type and other items to find matching components, we can directly locate the component item by setting the component item (class full name ), this method is generally used to connect the internal components of the application to the data transmission carrier in the extras item intent, and stores data through key-value pairs, the implementation component can obtain the key value through the key. The flags item flags can be used to specify how the Component Management Service constructs the implementation component, which is built in the new task stack, it is still built in the original Task Stack and is often used to change the task model and process model intent of the implementation components. addflags (intent. Flag_activity_new_task);
// Build intent. addflags (intent. Flag_activity_clear_top); // Clear the components at the top of the current job Stack

Each data item of an intent object is not used independently. They are usually mutually constrained by mutual cooperation and constitute an inter-component communication protocol. Intent objects can be divided into two types: one is the precise description of the intent that implements the component, the other is the fuzzy description of the intent that implements the component, and the precise description of the intent that implements the component requires a clear understanding of the implementation component (coupling ), fuzzy Description of the intent that implements the component requires the Component Management Service to perform component matching (completely decoupled). The intent filter object corresponds to the data items of the intent object one-to-one, intent filter is used to describe the functions implemented by the component. The functions implemented by the component can be dynamically set through the intent filter object, or you can configure and set the intent filter object in the configuration file. Pay attention to the following points: 1. Multiple action items can be set and the relationship between them is or. That is to say, as long as an action is satisfied, the intent object request can be accepted. 2. You can set multiple category items. That is to say, you can accept intent object requests only by meeting one of the constraints.

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.