I have seen so many different confusing explenations..
我看到过许多令人困惑的解释。
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
What is the meaning of
这是什么意思
<action android:name="android.intent.action.MAIN" />
and
和
<category android:name="android.intent.category.LAUNCHER" />
and
和
<category android:name="android.intent.category.DEFAULT" />
2 个解决方案
#1
53
android.intent.action.MAIN
means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.
main表示该活动是应用程序的入口点,即当您启动应用程序时,将创建该活动。
From the docs
从文档
ACTION_MAIN with category CATEGORY_HOME -- Launch the home screen.
Also,from here
另外,从这里
Activity Action Start as a main entry point, does not expect to receive data.
活动动作开始作为主要入口点,不期望接收数据。
android.intent.category.DEFAULT 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. 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.
默认值主要用于隐式意图。如果您的活动希望由一个隐含的意图开始,它应该包括这个catetory在它的过滤器。如果您的活动可能是由一个隐式意图启动的,而没有指定特定的类别给它,那么它的意图过滤器应该包含这个类别。
android.intent.category.LAUNCHER
android.intent.category.LAUNCHER
category -- Gives additional information about the action to execute.
category——提供关于要执行的操作的附加信息。
CATEGORY_LAUNCHER
means it should appear in the Launcher as a top-level application
CATEGORY_LAUNCHER意味着它应该作为一个*应用程序出现在启动程序中
See the docs..
看医生. .
- http://developer.android.com/reference/android/content/Intent.html
- http://developer.android.com/reference/android/content/Intent.html
- http://developer.android.com/guide/topics/manifest/action-element.html
- http://developer.android.com/guide/topics/manifest/action-element.html
#2
69
ACTION_MAIN
is considered an entry point for the application. Usually, it combines with CATEGORY_LAUNCHER
in an <intent-filter>
to indicate an activity that should appear in the home screen's launcher, or in anything else that considers itself to be a launcher. Such "launchers" can query PackageManager
, using queryIntentActivities()
, to find such activities and display them to the user.
ACTION_MAIN被认为是应用程序的入口点。通常,它与
However, ACTION_MAIN
can be used in combination with other categories for other specialized purposes. For example, CATEGORY_CAR_DOCK
with ACTION_MAIN
indicates an activity that should be considered a candidate to be shown when the user drops their phone into a manufacturer-supplied car dock.
但是,ACTION_MAIN可以与其他类别结合使用,用于其他特定目的。例如,CATEGORY_CAR_DOCK with ACTION_MAIN指出当用户将他们的手机放入制造商提供的汽车基座中时,应该将该活动视为候选活动。
When an Intent
is used with startActivity()
, if the Intent
is not already placed into a category, it is placed into CATEGORY_DEFAULT
. Hence, an <activity>
<intent-filter>
needs to specify some <category>
, using <category android:name="android.intent.category.DEFAULT" />
if nothing else.
当意图与startActivity()一起使用时,如果意图还没有被放到一个类别中,那么它将被归入CATEGORY_DEFAULT。因此,
#1
53
android.intent.action.MAIN
means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.
main表示该活动是应用程序的入口点,即当您启动应用程序时,将创建该活动。
From the docs
从文档
ACTION_MAIN with category CATEGORY_HOME -- Launch the home screen.
Also,from here
另外,从这里
Activity Action Start as a main entry point, does not expect to receive data.
活动动作开始作为主要入口点,不期望接收数据。
android.intent.category.DEFAULT 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. 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.
默认值主要用于隐式意图。如果您的活动希望由一个隐含的意图开始,它应该包括这个catetory在它的过滤器。如果您的活动可能是由一个隐式意图启动的,而没有指定特定的类别给它,那么它的意图过滤器应该包含这个类别。
android.intent.category.LAUNCHER
android.intent.category.LAUNCHER
category -- Gives additional information about the action to execute.
category——提供关于要执行的操作的附加信息。
CATEGORY_LAUNCHER
means it should appear in the Launcher as a top-level application
CATEGORY_LAUNCHER意味着它应该作为一个*应用程序出现在启动程序中
See the docs..
看医生. .
- http://developer.android.com/reference/android/content/Intent.html
- http://developer.android.com/reference/android/content/Intent.html
- http://developer.android.com/guide/topics/manifest/action-element.html
- http://developer.android.com/guide/topics/manifest/action-element.html
#2
69
ACTION_MAIN
is considered an entry point for the application. Usually, it combines with CATEGORY_LAUNCHER
in an <intent-filter>
to indicate an activity that should appear in the home screen's launcher, or in anything else that considers itself to be a launcher. Such "launchers" can query PackageManager
, using queryIntentActivities()
, to find such activities and display them to the user.
ACTION_MAIN被认为是应用程序的入口点。通常,它与
However, ACTION_MAIN
can be used in combination with other categories for other specialized purposes. For example, CATEGORY_CAR_DOCK
with ACTION_MAIN
indicates an activity that should be considered a candidate to be shown when the user drops their phone into a manufacturer-supplied car dock.
但是,ACTION_MAIN可以与其他类别结合使用,用于其他特定目的。例如,CATEGORY_CAR_DOCK with ACTION_MAIN指出当用户将他们的手机放入制造商提供的汽车基座中时,应该将该活动视为候选活动。
When an Intent
is used with startActivity()
, if the Intent
is not already placed into a category, it is placed into CATEGORY_DEFAULT
. Hence, an <activity>
<intent-filter>
needs to specify some <category>
, using <category android:name="android.intent.category.DEFAULT" />
if nothing else.
当意图与startActivity()一起使用时,如果意图还没有被放到一个类别中,那么它将被归入CATEGORY_DEFAULT。因此,