Android activity-use intent Filter

Source: Internet
Author: User

The <activity> element can also use the <intent-filter> element to specify various intent filters to declare how other application components can activate them.

 

When you use the androidsdk tool to create a new application, the automatically created activity contains an intent filter that declares that the activity responds to the "Main" action, and the filter is placed in the "launcher" category. The filter statement is as follows:

<Activity Android: Name = ". exampleactivity" Android: icon = "@ drawable/app_icon">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>

 

<Action> the element specifies that this is the main entry of the application. <Category> the element specifies that the activity should be listed in the Application Loader of the system (allowing users to load the activity)

 

If you want your application to be self-contained and do not allow other applications to activate its activity, no other intent filter is required, you only need to configure the "Main" action and "launcher" category for the activity as shown in the preceding example. Activities that do not want to be valid for other applications should not have intent filters, and you can start them in your own applications.

 

However, if you want your activity to respond to implicit intent from other applications (including the application itself), you must define an additional intent filter for your activity. For each intent type that you want to respond to, you must include an <action> element in the <intent-filter> element and optional <Category> and <DATA> elements. These elements specify the intent type that your activity can respond.

 

For more information about the intent that the activity can respond to, see the intents and intent filters documents.

 

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.