Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of "android.intent.category.DEFAULT"?

What is the purpose of using android.intent.category.DEFAULT in the Category field of Intent Filters?

like image 916
Pravy Avatar asked Apr 20 '11 08:04

Pravy


People also ask

What is intent category default?

The category DEFAULT is automatically applied to all implicit intents (by default) so because of the reason above every Activity that want to receive any implicit intent at all has to include this category in its Intent-filter.

What is the purpose of categories in intents?

Show activity on this post. The category's alone are useless, they are used to describe a possible target for an "implicit intent" in an intent-filter . When you know which class/activity you want to launch and use startActivity() or startActivityForResult() , it's called an "explicit intent".

What is the purpose of an intent in Android?

An Intent object carries information that the Android system uses to determine which component to start (such as the exact component name or component category that should receive the intent), plus information that the recipient component uses in order to properly perform the action (such as the action to take and the ...

What is the purpose of the intent filter?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.


2 Answers

Categories are used for implicit Intents. So, If your Activity can be started by an implicit Intent when no other specific category is assigned to activity, activity's Intent filter should include this category. (even if you have other categories in the Intent filter). If you are sure that your activity must be called with any other Category, don't use the Default.

Setting Category to Default doesn't mean that this Activity will be used by default when your app launches. The Activity just says to system that " Oh I could be started, even if the starter Intent's category is set to Nothing at all ! "

like image 78
Özgür Avatar answered Sep 29 '22 12:09

Özgür


This category is mainly used for implicit intents. If your activity wishes to be started by an implicit intent it should include this catetory in its filter.

I think the term "default" should be understood as "default candidate". If the action on a piece of data resolves to multiple activities, then Android will present all candidates to the user and the user can select his preferred default.

Reference:

http://developer.android.com/guide/components/intents-filters.html

Extract from that page:

Android treats all implicit intents passed tostartActivity() as if they contained at least one category: "android.intent.category.DEFAULT" (the CATEGORY_DEFAULT constant). Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters. (Filters with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings are the exception. They mark activities that begin new tasks and that are represented on the launcher screen. They can include "android.intent.category.DEFAULT" in the list of categories, but don't need to.)

like image 27
Bruno Ranschaert Avatar answered Sep 29 '22 10:09

Bruno Ranschaert