Android Development Intent Application Overview

Source: Internet
Author: User
Tags gettext

Original:

Http://bbs.gfan.com/android-93448-1-1.html

Today, we look at intent, yes, that is the more difficult to understand the previous thing, hope through this article, you find that the preceding sentence is actually wrong.
As mentioned earlier, intent is like the two-sided glue between activity, in the literal sense: "intention, intention, purpose", can basically interpret the role of this object. It contains information that tells us what's going on and what we want to do about it. I feel very much like the events in the previous event-driven event, and the difference is that it contains not only events but also some data information. Intent can also say that the current event and some data are described in the same way as a requirement statement, and then Android will find an activity for it based on the intent instructions, and give the intent to the activity. Looks like intent is a lonely-marriage ad. Oh, intent presents some of his own descriptions (the difference is that he describes himself, not the others), and then Android finds out when the Activity is based on these descriptions.
There are two kinds of intent, one is explicit intent and the other is implicit intent. The explicit intent will declare in its own description who (which activity) receives the processing of this intent. The explicit intent is that I already have the right one, tell Android not to bother to find, you can directly locate the lover, such as the previous example:

Intent Intent = new Intent ();
Intent.putextra ("Name", Edittext.gettext (). toString ());
Intent.setclass (Activitylifecycle.this, Alertdialog.class);

Through the SetClass method, directly tell Android, this intent to alertdialog processing. You can also do the same thing by SetComponent (), Setclassname () and other methods.
In a general program, I think it's enough to use explicit intent. This program seems to be easy to understand, after all, most Android programs will not have too complex relationship between the activity.
In the other method in the previous article, the implicit intent is used. Implicit intent, more subtle, relatively confused, relatively vague, there is no clear goal, and more pessimistic, will not ask the other side, just describe the situation of their own, meaning that I am the description of such a person, who can accept, who can be recruited. :)

Intent Intent = new Intent ();
Intent.putextra ("Name", Edittext.gettext (). toString ());
Intent.setaction ("Com.roiding.sample.action.MAIN");

The way intent describes himself is:

The

Action is used to indicate the action performed, such as Action_view, Action_edit, Action_main, which are standard actions defined in Android, and the developer can define his or her own desired action, expressed in strings. More standard action see here. The
Category describes the additional information about the action, which I have never quite understood, why it was designed, and so far, my understanding of it is that it is like an action category, for example: Category_launcher, Category_alternative. belong to the category of Category_launcher, can be placed in the top-level list of Android (similar to the nine Gongge interface) is executed, belongs to the Category_default category, can be used startactivity (intent) To start the activity, and so on. These actions are Android-defined, so the custom category does not know what the meaning, more standard category see here. The data that the data action operates on will be carried to the Activity,uri format that receives it, like a dowry. The concept of URIs is consistent with the traditional concept of URIs, followed by RFC 2396. And the URI is finally provided by the ContentProvider, so it will involve the concept of contentprovider, here also temporarily do not explain, just need to know the data of the declaration, just like a URL, through this URL, You can find the data provided by the ContentProvider that provided the URL, and then you can manipulate the data. Does the data appear to overlap with the previous extras function? As I understand it, data can actually be passed into the extras, but it is intended to be presented separately. In the back of the intentfilter will be explained.

Since it has been likened to a marriage ad, the intent is likened to the need for a marriage, then what is the candidate chosen by the Android system?
In front of this document: Androidmanifest.xml, and at that time likened it to a hukou, this is good, all the age-appropriate youth (Activity) in this large hukou, according to the needs of intent directly in the hukou search can be. And how do you know which age-appropriate youth meets the requirements?
In the Androidmanifest file, a description of each age-appropriate youth (Activity) is Intent-filter, which shows what kind of needs the current age-appropriate young people are willing to receive, So when intent is consistent with the instructions in this intent-filter, intent finds activity.
Thus, when all the instructions of a intent are accepted by the intent-filter of the activity, the activity is one of the candidates. If more than one activity becomes a candidate, Android prompts you to manually select one from multiple activity as the final intent receive performer when the program is running.
For activity, in its intent-filter, there can be multiple actions, multiple category, multiple data, so there can be more than one intent to match.
Speaking of which, the previous question about the overlap of data and extras functions seems to have not been solved, so the important role of this data is that it provides a mechanism for reverse selection, so that the activity can also ask for intent, The data required for intent must be one of the data declared in Intent-filter (because there can be more than one data). This is very important, or else there will be activitynotfoundexception and other mistakes.
To this article, the general Android interface programming should be enough, and for ContentProvider, Adapter, services, etc., in general applications, can not be considered at all. Wait until you have to use it.

Android Development Intent Application Overview

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.