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

AndroidIntentfilter

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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 ! "

Solution 2 - Android

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.)

Solution 3 - Android

Activities will need to support the CATEGORY_DEFAULT so that they can be found by Context.startActivity().

In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category. If we do not declare it in our intent filter, no implicit intents will resolve to our activity.

Solution 4 - Android

It is actually to make sure your other activities can be called out when the app is running. LAUNCHER will make the activity that has it the first activity that starts. To use intents to get to the other activities, they have to be listed as "actual" activities by putting DEFAULT. That is from what I know so don't quote me if it's wrong.

Solution 5 - Android

It is used to declare some operation as default action (as its name suggest). Lets consider we have a notepad app(referring to android notepad sample). The first page of app consists of a list of all notepad files. When one notepad file is selected one of the operations like edit note, delete note etc can be performed. But I want to make edit as my default action which means when i press center button of my keypad,edit window should be open.

Solution 6 - Android

category:

android.intent.category.DEFAULT

Matches any implicit Intent. This category must be included for your Activity to receive any implicit Intent.

https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..%2Fandroid-training#6

Solution 7 - Android

https://developer.android.com/guide/components/intents-filters

> To receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category. If you do not declare this category in your intent filter, no implicit intents will resolve to your activity.

Solution 8 - Android

Before an implicit Intent is accepted by an Activity the Intent must pass a category test: Each category in the Intent must match the exact same category in the Intent-filter of the Activity.

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.

Source

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPravyView Question on Stackoverflow
Solution 1 - AndroidÖzgürView Answer on Stackoverflow
Solution 2 - AndroidBruno RanschaertView Answer on Stackoverflow
Solution 3 - AndroidShinoo GoyalView Answer on Stackoverflow
Solution 4 - AndroidCHTView Answer on Stackoverflow
Solution 5 - AndroidPrernaView Answer on Stackoverflow
Solution 6 - AndroidRIKView Answer on Stackoverflow
Solution 7 - AndroidkrekerView Answer on Stackoverflow
Solution 8 - AndroidMattSchmattView Answer on Stackoverflow