When developing an Android application, you will see an
android.intent.action.MAIN in your
An example of the manifest file could be as follows:
<activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
android.intent.action.MAIN is defined to let the Android Operating System (OS) knows what Activity class to run when the application is started.
In the above example, the
<intent-filter> tag is added to the
<activity> tag with the name of
By setting the
action.MAIN intent filter, the Android OS will run the
MainActivity class when you open the application.
When you generate an Android application using Android Studio, the
action intent filter is usually paired with the
category intent filter of
category filter is used to let Android OS know what activity to run when the application is started from the launcher.
In Android terminology, a launcher is a specific type of Android application that can be used to start other applications.
In Android phones and tablets, the launcher is the home screen of the device.
category intent filters are required to determine the Activity class to run when the application is launched from an Android device.
Without them, the application won’t be launched and Android Studio will respond with the following error:
Could not identify launch activity: Default Activity not found Error while Launching activity Failed to launch an application on all devices
android.intent.action.MAIN only let Android OS know the main activity to run, you can pair it with other category filters.
For example, you can pair an
action.MAIN filter with the
category.DESK_DOCK filter to define the Activity to run when the device is inserted into a desk dock.
To conclude, a standard Android phone application requires an
activity with both
The filters let the Android OS know what Activity class to look for when the application is launched.