Home » Android » intentfilter – What is the purpose of "android.intent.category.DEFAULT"?

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

Posted by: admin March 11, 2020 Leave a comment

Questions:

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

How to&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 !

Answer:

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

Answer:

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.

Answer:

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.

Answer:

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.

Answer:

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.

Answer:

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