Understand the specific functions of Android. Intent. Category. Launcher

Source: Internet
Author: User

Android. Intent. Category. LauncherWhat is the specific function? I will make a small example to help you understand

<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 multiple activities, each of which is at the same level. Which activity is the first to start when a program is started? Some programs may need to be displayed in the program list, while others do not. How to define it? Android. Intent. Action. Main determines the activity Android. Intent. Category. launcher that the application first starts to determine whether the application is displayed in the program list.

Because your program may have many activities
As long as the xml configuration file contains such an intent-filter and the launcher, this activity is the first activity to run when you click the program.

<Activity Android: Name = "apact">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>

</Intent-filter>
</Activity>
<Activity Android: Name = "urlact">
<Intent-filter>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>

If the code looks like this, will it still be displayed in the list, that is, main and launcher are used together?

<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>
<Action Android: Name = "android. Intent. Action. Main"
/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>

If so, two icons will appear in the list.

Used to set the activity to be enabled by default when the simulator is started.

Why Android. Intent. Category. Default?

It means that each implicit intent sent by startactivity () method has at least one category, that is"android.intent.category.DEFAULT", So any activity that wants to receive an implicit intent should include"android.intent.category.DEFAULT"
Category. Otherwise, intent matching fails.

The following information can also be obtained from the above discussion:
1. An intent can have multiple category items, but at least one of them is the default category.
2. The activity receives the intent only when all intent category matches.

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.