“android.intent.category.DEFAULT”的目的是什么?

时间:2022-02-12 16:26:00

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

在Intent Filters的Category字段中使用android.intent.category.DEFAULT的目的是什么?

5 个解决方案

#1


85  

Categories are used for implicit Intents. So, If your Activity might be started by an implicit Intent when no specific category is assigned to it, its 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.

类别用于隐式Intents。因此,如果您的Activity可能在没有为其分配特定类别时由隐式Intent启动,则其Intent过滤器应包含此类别。(即使您在Intent过滤器中有其他类别)。如果您确定必须使用任何其他类别调用您的活动,请不要使用默认值。

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

将“类别”设置为“默认”并不意味着在应用启动时默认使用此“活动”。活动只是告诉系统“哦,我可以开始,即使首发Intent的类别设置为Nothing!”

#2


22  

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.

此类别主要用于隐式意图。如果您的活动希望通过隐式意图启动,则应在其过滤器中包含此catetory。

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.

我认为“默认”一词应理解为“默认候选人”。如果对一条数据的操作解析为多个活动,则Android将向用户显示所有候选项,并且用户可以选择其首选默认值。

Reference:

参考:

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

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

Android会将通过tostartActivity()传递的所有隐式意图视为至少包含一个类别:“android.intent.category.DEFAULT”(CATEGORY_DEFAULT常量)。因此,愿意接收隐式意图的活动必须在其意图过滤器中包含“android.intent.category.DEFAULT”。 (带有“android.intent.action.MAIN”和“android.intent.category.LAUNCHER”设置的过滤器是例外。它们标记开始新任务的活动,并在启动器屏幕上显示。它们可以包含“android.intent .category.DEFAULT“在类别列表中,但不需要。)

#3


1  

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.

实际上,确保在应用程序运行时可以调出您的其他活动。 LAUNCHER将使活动成为第一个开始的活动。要使用意图来进行其他活动,必须通过输入DEFAULT将它们列为“实际”活动。这是我所知道的,所以如果它错了就不要引用我。

#4


1  

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

活动需要支持CATEGORY_DEFAULT,以便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.

要接收隐式意图,必须在intent过滤器中包含CATEGORY_DEFAULT类别。方法startActivity()和startActivityForResult()将所有意图视为已声明CATEGORY_DEFAULT类别。如果我们不在我们的intent过滤器中声明它,则不会将隐式意图解析为我们的活动。

#5


0  

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.

它用于将某些操作声明为默认操作(顾名思义)。让我们考虑一下我们有一个记事本应用程序(指的是android记事本示例)。应用程序的第一页包含所有记事本文件的列表。当选择一个记事本文件时,可以执行编辑注释,删除注释等操作之一。但是我想将编辑作为我的默认动作,这意味着当我按下键盘的中心按钮时,编辑窗口应该打开。

#1


85  

Categories are used for implicit Intents. So, If your Activity might be started by an implicit Intent when no specific category is assigned to it, its 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.

类别用于隐式Intents。因此,如果您的Activity可能在没有为其分配特定类别时由隐式Intent启动,则其Intent过滤器应包含此类别。(即使您在Intent过滤器中有其他类别)。如果您确定必须使用任何其他类别调用您的活动,请不要使用默认值。

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

将“类别”设置为“默认”并不意味着在应用启动时默认使用此“活动”。活动只是告诉系统“哦,我可以开始,即使首发Intent的类别设置为Nothing!”

#2


22  

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.

此类别主要用于隐式意图。如果您的活动希望通过隐式意图启动,则应在其过滤器中包含此catetory。

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.

我认为“默认”一词应理解为“默认候选人”。如果对一条数据的操作解析为多个活动,则Android将向用户显示所有候选项,并且用户可以选择其首选默认值。

Reference:

参考:

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

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

Android会将通过tostartActivity()传递的所有隐式意图视为至少包含一个类别:“android.intent.category.DEFAULT”(CATEGORY_DEFAULT常量)。因此,愿意接收隐式意图的活动必须在其意图过滤器中包含“android.intent.category.DEFAULT”。 (带有“android.intent.action.MAIN”和“android.intent.category.LAUNCHER”设置的过滤器是例外。它们标记开始新任务的活动,并在启动器屏幕上显示。它们可以包含“android.intent .category.DEFAULT“在类别列表中,但不需要。)

#3


1  

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.

实际上,确保在应用程序运行时可以调出您的其他活动。 LAUNCHER将使活动成为第一个开始的活动。要使用意图来进行其他活动,必须通过输入DEFAULT将它们列为“实际”活动。这是我所知道的,所以如果它错了就不要引用我。

#4


1  

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

活动需要支持CATEGORY_DEFAULT,以便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.

要接收隐式意图,必须在intent过滤器中包含CATEGORY_DEFAULT类别。方法startActivity()和startActivityForResult()将所有意图视为已声明CATEGORY_DEFAULT类别。如果我们不在我们的intent过滤器中声明它,则不会将隐式意图解析为我们的活动。

#5


0  

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.

它用于将某些操作声明为默认操作(顾名思义)。让我们考虑一下我们有一个记事本应用程序(指的是android记事本示例)。应用程序的第一页包含所有记事本文件的列表。当选择一个记事本文件时,可以执行编辑注释,删除注释等操作之一。但是我想将编辑作为我的默认动作,这意味着当我按下键盘的中心按钮时,编辑窗口应该打开。