Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" /> 
like image 479
Gero Avatar asked Aug 09 '14 14:08

Gero


People also ask

What is action and category in android?

action : Declares the intent action accepted, in the name attribute. The value must be the literal string value of an action, not the class constant. category: Declares the intent category accepted, in the name attribute.

What is intent in android with example?

Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc. It is generally used with startActivity() method to invoke activity, broadcast receivers etc. The dictionary meaning of intent is intention or purpose.

What are intents in Android system?

Android Intent can be defined as a simple message objects which is used to communicate from 1 activity to another. Intents define intention of an Application . They are also used to transfer data between activities.

What are the different types of intent?

There are two types of intents in android: Implicit and. Explicit.


2 Answers

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.

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.

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.

like image 197
CommonsWare Avatar answered Oct 05 '22 13:10

CommonsWare


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.

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.

android.intent.category.LAUNCHER

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

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

See the docs..

  1. http://developer.android.com/reference/android/content/Intent.html
  2. http://developer.android.com/guide/topics/manifest/action-element.html
like image 36
Lal Avatar answered Oct 05 '22 13:10

Lal