When to add Android.intent.category.DEFAULT and launcher?

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/ccccdddxxx/article/details/7843070

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:

Intent intent= New Intent (this, 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: Android.intent.category.MAIN and Android.intent.category.LAUNCHER do not need to join the Android.intent.category.DEFAULT in the filter, of course, not to ask Problem.

We define the activity if accept implicit intent words, intent filer must add android.intent.category.DEFAULT this category.

What does Android.intent.category.LAUNCHER have in particular? I don't have any difference between adding and feeling in XML. Who can explain it!

<activity android:name= "Apact" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name= "Urlact" >
<intent-filter>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

An application can have more than one activity, and each activity is at the same level, which activity is started first when the program is started? Some programs may need to be displayed in the list of programs, some of which are not required. How do you define it? Android.intent.action.MAIN determines the activity Android.intent.category.LAUNCHER the application starts first determines whether the application appears in the program list

Because your program may have a lot of activity.
As long as there is such a intent-filter in the XML configuration file, and there is this launcher in it, then this activity is the activity that first runs when the program is clicked.

Now that you have only one activity, it doesn't matter if you add it.

Activity that is set to open as default when the emulator starts

3, why Join Android.intent.category.DEFAULT

This means that every implicit Intent issued by the StartActivity () method has at least one category, which is " android.intent.category.DEFAULT ", so as long as the Activity that wants to receive an implicit Intent should include the android.intent.category.DEFAULT category , or it will cause the Intent match to fail.

The following information can also be obtained from the above discussion:
1, a Intent can have more than one category, but there will be at least one, is also the default category.
2, only Intent all category matches, the Activity will receive this Intent.

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.