android.intent.action.MAIN 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25219551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:14:26  来源:igfitidea点击:

What is the meaning of android.intent.action.MAIN?

androidandroid-intentandroid-activity

提问by Gero

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

采纳答案by Lal

android.intent.action.MAINmeans that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.

android.intent.action.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.

Activity Action Start 作为一个主要的入口点,不期望接收数据。

android.intent.category.DEFAULTis 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.

android.intent.category.DEFAULT主要用于隐式意图。如果您的活动希望通过隐式意图启动,则应在其过滤器中包含此类别。如果您的 Activity 可能在没有指定特定类别的情况下由隐式 Intent 启动,则其 Intent 过滤器应包含此类别。

android.intent.category.LAUNCHER

android.intent.category.LAUNCHER

category -- Gives additional information about the action to execute.

category -- 提供有关要执行的操作的附加信息。

CATEGORY_LAUNCHERmeans it should appear in the Launcher as a top-level application

CATEGORY_LAUNCHER意味着它应该作为顶级应用程序出现在启动器中

See the docs..

查看文档..

  1. http://developer.android.com/reference/android/content/Intent.html
  2. http://developer.android.com/guide/topics/manifest/action-element.html
  1. http://developer.android.com/reference/android/content/Intent.html
  2. http://developer.android.com/guide/topics/manifest/action-element.html

回答by CommonsWare

ACTION_MAINis considered an entry point for the application. Usually, it combines with CATEGORY_LAUNCHERin 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被视为应用程序的入口点。通常,它与CATEGORY_LAUNCHERin结合<intent-filter>以指示应出现在主屏幕启动器中的活动,或任何其他认为自己是启动器的活动。此类“启动器”可以查询PackageManager、使用queryIntentActivities()、查找此类活动并将其显示给用户。

However, ACTION_MAINcan be used in combination with other categories for other specialized purposes. For example, CATEGORY_CAR_DOCKwith ACTION_MAINindicates 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_DOCKwithACTION_MAIN表示当用户将手机放入制造商提供的车载底座时,应将其视为显示候选的活动。

When an Intentis used with startActivity(), if the Intentis 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.

当 anIntent与 一起使用时startActivity(),如果Intent尚未放入类别中,则将其放入 中CATEGORY_DEFAULT。因此, an<activity><intent-filter>需要指定some<category><category android:name="android.intent.category.DEFAULT" />如果没有别的则使用。

回答by Shubham Soni

<action android:name="android.intent.action.MAIN"/>

Is the main activity for this application

是此应用程序的主要活动

 <category android:name="android.intent.category.LAUNCHER" />

It is in the LAUNCHER category, meaning it gets an icon in anything that thinks of itself as a “launcher”, such as the home screen

它属于 LAUNCHER 类别,这意味着它会在任何自认为是“启动器”的地方(例如主屏幕)中获得一个图标

 <category android:name="android.intent.category.DEFAULT" />

The call to startActivity() will always add the DEFAULT category if no other category is specified.

如果未指定其他类别,则调用 startActivity() 将始终添加 DEFAULT 类别。

Generally just add android.intent.category.DEFAULTeven if you have other Categories. This will guarantee that if Requesting Intent doesn't provide any Categories while starting the intent using startActivity(intent), then your Receiving Activity can also receive those Intents..

android.intent.category.DEFAULT即使您有其他类别,通常也只需添加。这将保证如果在使用 开始意图时请求意图不提供任何类别startActivity(intent),那么您的接收活动也可以接收这些意图。

Source: The Busy Coders Guide to Android Development

资料来源:Android 开发忙碌的程序员指南

https://commonsware.com/Android/

https://commonsware.com/Android/