use of Android intent
What are the three main components--activity, service, and broadcast receiver activated?
Answer: Intent is a runtime-bound message mechanism, and the three components--activity, service, and broadcast receiver are all activated by the message, which is intent.
A intent object consists of six attributes, please list these six attributes each.
Answer: The component name (Component name), action, data, category, additional information (Extra), and flags (flags).
Answer: In an Android application, it is mainly composed of some components (activity,service,contentprovider,etc.) In the communication between these components, the intent assists the completion.
As some people on the internet said, intent is responsible for the operation of the application in the action, the action involved in data, additional data description, Android according to the description of this intent, is responsible for finding the corresponding component, the intent passed to the calling component, and complete the call of the component. Intent is where the decoupling between the caller and the callee is implemented.
In intent delivery process, to find the target consumer (another activity,intentreceiver or service), that is, the intent responder, there are two ways to match:
1, display matching (Explicit):
public testb extents activity
{
.........
};
public class Test extends activity
{
......
public void switchactivity ()
{
Intent i = New intent (test.this, testb.class);
this.startactivity (i);
}
}
The code is concise, executes the switchactivity () function, and immediately jumps to the activity named Testb.
2. Implicit matching (implicit):
Implicit matching, first to match several values of intent: Action, Category, data/type,component
If you fill in the componet is the Test.class in the example above) this forms a display match. So this section only tells the first few matches. The matching rule is the maximum matching rule,
1. If you fill in the action, If there is an activity in the Intentfilter segment of a program that contains the same action as defined in the manifest.xml, then this intent matches the target action, and if no type is defined in the filter segment, Category, then the activity is matched. But if you have more than two programs in your phone, a dialog box will pop up to show you the message.
The value of action has a lot of pre-defined in Android, and if you want to go directly to your own defined intent receiver, you can add a custom action value to the recipient's Intentfilter (and set the category value to " Android.intent.category.DEFAULT "), set the action in your intent to intent, and you can jump directly to your own intent receiver. Because this action is unique in the system.
2, Data/type, you can use the URI as data, such as URI uri = Uri.parse (http://www.google.com);
Intent i = new Intent (Intent.action_view,uri); During the Intent distribution of the cell phone, the data type is judged according to the http://www.google.com scheme.
The brower of the handset can match it, in the intenfilter of Brower Manifest.xml first have Action_view Action, also can handle http: the type,
3, as for classification category, generally do not go in the intent set it, if you write intent receiver, in manifest.xml activity Intentfilter contains Android.category.DEFAULT So that all Intent that do not set the category (Intent.addcategory (String c);) will match this category.
4, Extras (additional information), is a collection of all other additional information. You can use extras to provide extended information for your component, such as, if you want to perform the "Send e-mail" action, you can save the e-mail message's title, body, and so on in extras, to the e-mail sending component.