The function and use method of explicit intent and implicit intent are analyzed.

Source: Internet
Author: User

an explicitIntentand implicitIntentfunction and use method parsing.

Intent, meaning in Chinese is intention. Is the thing that you want to do.

and using StartActivity (intentintent) or Startactivityforresult (intentintent) or any other method of using it, figuratively speaking, is referring to To do the things you want to do. (Do-you-wantto do)

First, the general introduction of their use differences:

1.Explicit Intent (Explicit intent): A component that is primarily used to invoke its own application (Activity,service), or that is explicitly intended to be invoked by other programs. (This is less used because it is rarely called)

2.Implicit Intent (implicit intent): Mainly used to start programs other than this program.

Then talk about how to use each other.

One: explicitintent:

Should there be a intent first before use? Let's create one first.

Create a method. Intent Intent = newintent (Context context,class<?> Class);

The next class parameter is the reflection of a class.

You can also remember the class name of the class that is the target activity. class;

Use:

startactivity (Intent) or startactivityforresult (intent);

And then it's ready.

Two Implicitintent

We parse it as a two-character identity.

First, the caller identity. (Just want to jump to the current application of another application)

The main way to create an implicit intent:

Initial band action:intent (String action)

Empty intent:intent ();

Initially with both action and uri:intent (String action, Uri URI);

In fact, these three methods use the difference is not small, but the initial set of parameters a little more than the construction method is sometimes easier.

Intent can also set or change parameter values after the build.

such as: Intent.setaction (String action) also has URI settings: SetData (URI uri), MIME type: SetType (), etc.

One thing to note is that if you need to set both the URI and the MIME type, use the Setdataandtype () method , because when you call SetData and Settype separately, They're going to make another one of their two failures. Why is it? Because in fact the URI also has the setting type, will conflict, overwriting another setting.

There are other attributes that are also critical. It is recommended to consult the Android development documentation. Because I personally say better, also than you do to find, to explore.

Calling an implicit intent is also the same as calling explicit.

When you call intent implicitly, if you want to start a program with a certain number of functions, such as when you use your personal want to send a file, there are many programs come out to let you choose it? such as Bluetooth, QQ or something. If there are multiple programs that can implement a feature, a list will appear to allow you to make a selection. Start the program directly with a single program.

So usually you do not know what to start the program, and the system itself started, so that the user experience is not very good? At this point, it is possible to implement a function that even though only a single program also appears in the selection box: Chooser.

Chooser itself is also a intent, but it is a intent with a selector attached.

Examples of Use:

Intent Intent =new Intent ();

...

Intent Chooser =intent.createchooser (intent,title);

The title here is the caption string for the selection box.

2. Receive implicit intent

What if you want your program to accept implicit intent from other programs?

Declare in the manifest file (Manifest) that you can receive an implicit intent of a type.

Such as:

<activityandroid:name= "Shareactivity" >

<intent-filter>

<action android:name= "Android.intent.action.SEND"/>

<category android:name= "Android.intent.category.DEFAULT"/>

<data android:mimetype= "Text/plain"/>

</intent-filter>

</activity>

First of all, to analyze the Chinese translation of Intent-filte. Intent (intended) filter.

So Why do we have this filter ?

First you think, if there is no filter this thing, then, when you want to start a program with a certain function, the system will not be able to identify which programs can use which functions, on the beep Phala all the references are listed. Isn't that a bad idea?

System by default, if an application does not have any intent filter (Intent-filter) then nothing can be audited by it.

The application can be imagined as a water dispenser, the intention filter is used to filter the water. So when a water dispenser (application) does not have a filter, do I prefer to let it not be approved for people to drink? It is easy to have a lot of harmful substances without filtration. Do you dare to drink it without filtration?

When we have a filter, we are relieved to be able to drink the water filtered through the filter (equivalent to the use of approved applications).

So, then, there's another question.

How to filter the intent?

The answer is, of course, a layer of filtering.

The data in the figure is a URI and MIME type.

As long as one path passes, it is passed, and you can use some of the specific features of the program.

If you want to see more details about intent, check out the official Android documentation.

The function and use method of explicit intent and implicit intent are analyzed.

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.