Android's Intent

Source: Internet
Author: User

Using Intent and intentfilrter for communication, Intent is divided into explicit and implicit intent, and is not configured explicitly.

It is generally preferred in the same application, because it is highly efficient.
Intent is the intent of Android for encapsulation, regardless of whether you want to start a new activity or service or broadcastreceiver, you need to
Intent to serve as a bridge.

The intent contains seven properties :
Component,category,action,data,type,extra and Flag, where Component is used to explicitly specify the target component that needs to be started.
The extra is used to carry data that needs to be exchanged.

The following is a detailed description:
Displays intent and implicit intent.
Start a new activity.
Note: The new activity must be configured in the manifest file.
Intent Intent = new (Mainactivity.this,secondactivity.class);//. Class suffix cannot be forgotten
StartActivity (Intent);
A display intent object can contain a maximum of one action property, but may contain multiple category properties.
Setaction (String str); Addcategory (String str);

You must specify the specific information for the component you are opening (the class of the package name Component name component).
You can use intent to invoke other applications of the system. If you have a local album set up on your network, be aware of adding permissions.
Intent Intent = new Intent ("PackageName", "classname");
StartActivity (intent);//Pay attention to configuring activity.
Little Flowers's video speaks very well.
The configuration is not configured explicitly.

Implicit intent: Explicit coupling is poor,
Describes the behavior of an action.
Intent Intent = new Intent ();
Intent.setaction ();//The system defaults to a number of action types.
Intent.setdata (Uri data);
StartActivity (Intent);
Need

An activity can be configured with multiple intent-filter, which can be invoked as long as one of these intents is satisfied.
An implicit intent can also set multiple actions, as long as one satisfies one and can be called.

The same application inside, self-activating their own things, recommended the use of explicit, high efficiency.
Different programs, activating someone else's app, or letting one of your own interfaces want to be activated by someone else
The use of hermit's intentions is recommended.
When using hermit intent
1. Check all the activity in the system to see if there are any activity that satisfies the condition.
2. If only one is used directly, but if there are multiple eligible activity then the list is displayed
3. If the exception is not thrown. Activity not found exception.

To move data from one activity to another activity:
Intent Intent = new Intent (this, secondactivity.class);
Intent.putextra ("name", name);

Eight basic data can be passed in the past including the string type, key-values the formation of storage data

StartActivity (Intent);
--------------------------------------------------------------------------
In Secondactivity's OnCreate ():
Intent Intent = Getintent ();
String name = Intent.getstringextra ("name");

Android's Intent

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.