Uses and uses of Android Android.intent.category.DEFAULT

Source: Internet
Author: User

1, to understand this problem, first need to figure out what is implicit (hidden) Intent what is explicit (clear) intent.

Explicit Intent explicitly specifies the acitivity to start, such as the following Java code:

[Java] view Plaincopyprint?

    1. intent intent=  new , b. class

Implicit intent does not explicitly specify which activity to start, but instead sets some intent filter to allow the system to filter the appropriate acitivity to start.

2, intent exactly to which activity, need to do three matches, one is action, one is category, one is data.

Theoretically, if intent does not specify category, then whatever the contents of the intent filter should be matched. However, if it is implicit intent,android default to add a category_default, so if intent If the category is not Android.intent.category.DEFAULT in filter, the match test will fail. So, if your activity supports receiving implicit intent, be sure to include Android.intent.category.DEFAULT in intent filter.

Exceptions are:

[Java] view Plaincopyprint?

  1. <intent-filter>

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

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

  4. </intent-filter>


There is no need to join the Android.intent.category.DEFAULT, of course, there is no problem. This is the first startup activity that the app launches by default (with so many activity for each app, one must be the first one to start)

If you define an activity to be initiated implicitly, you must add Android.intent.category.DEFAULT to the ANDROIDMANIFAST.XM, otherwise it will not work.

In addition, there are many uses for category

For example, make a desktop, press the home button to start your own application

[HTML] view Plaincopyprint?

  1. < activity   

  2.              android:name ". Mainactivity "    

  3.              android:label = "@string/ App_name "     

  4. < Intent-filter >   

  5. <Action Android:name="Android.intent.action.MAIN" />  

  6. <category Android:name="Android.intent.category.LAUNCHER"/>  

  7. <category Android:name="Android.intent.category.HOME" />  

  8.              </ intent-filter >,   

  9. </ Activity >   

How to configure the three matching data in intent, and simply say

That is, when you do not directly specify the activity to jump to, provide intent with some relevant parameters, let it automatically and androidmanifest.xml in the existing activity to match

Intentfilter three main parameters in XML: Action,categary,data.

We can specify this three parameters through the intent constructor or the method provided by intent:

[Java] view Plaincopyprint?

    1. Intent.setaction (action);

    2. Intent.setdata (data);

    3. Intent.addcategory (category);


Uses and uses of Android Android.intent.category.DEFAULT

Related Article

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.