Use of intent in Android

Source: Internet
Author: User

Intent is divided into implicit intent and explicit intent:

Explicit intent means using intent objects to explicitly convey the intent of an activity class, which means that we can clearly know what to do next.

Often we use implicit intent to complete an application's call to another application.

The following I will be based on their understanding of the simple introduction of the use of intent.

Show intent, generally our use of it is

Intent it = new Intent ();

It.setclass (XX,XX);

StartActivity (IT), this is the simplest use, others do not do too much to explain.

However, how should we use implicit intent?


The specific use is as follows, create a new b.activity, in its configuration file we add <INTENT-FILTER> in which write <Action> and <category>:
In the same application, when we use implicit intent, we configure the activity that needs to jump in the Mianfest.xml file:


<activity android:name= "B" >
<intent-filter>
<action android:name= "com.example.alertdalog.intent.action.b"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

It is important to note that we must add the category attribute when configuring (the implicit intent contains at least "Android.intent.category.DEFAULT" (corresponding to the Category_default constant). Therefore, an activity that wants to receive implicit intent must include "Android.intent.category.DEFAULT" in the intent filter. ), if not joined, force close will appear at runtime.

In addition we can name any string in the action name, but for convenience we define name as a general
The package name is used. intent.action. Class name

In general, we use the a.class that we need to pass.
We can build constants for convenience
public static final String Action = "name";
StartActivity (new Intent (class name). Action));
It is important to note that through implicit intent, activity can be initiated across apps, and if an activity only allows access within one app, but not across apps

Our configuration is to add exported= "false" to the activity property, which means, that is, whether it can be exported,
Select False to indicate that you cannot export

Use of intent in Android

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.