Search code examples
androidandroid-intentandroid-implicit-intent

What does it mean when two or more activities, each having intent-filter with action=android.intent.action.ACTION_MAIN?


Doc says https://developer.android.com/reference/android/content/Intent.html#ACTION_MAIN is an entry point.

Example code:

 <activity android:name="org.A.A"
            android:theme="@style/NoTitle"
            android:screenOrientation="behind"
            android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

        <activity android:name="org.A.C"
            android:theme="@style/NoTitle"
            android:launchMode="singleTop"
            android:screenOrientation="behind">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

        <activity android:name="org.A.B"
            android:theme="@style/NoTitle"
            android:launchMode="singleTop"
            android:screenOrientation="behind">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

1) So using android.intent.action.ACTION_MAIN acts as an entry point to the parent component (parent component I mean the activity or receiver or service)?

2) If yes, Entry point from where, as there is no CATEGORY mentioned.


Solution

  • Android apps are composed of different components. e.g. Activity, Service, BroadcastReceiver, and ContentProvider and each component can act as an entry point of the app.

    Let's take activity as an example, you have defined an activity in your application with following action

    <intent-filter>
         <action android:name="com.yourapp.SOME_ACTION" />
         <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
    

    and I start an activity in my app with following intent.

    Intent intent = new Intent("com.yourapp.SOME_ACTION"); // same action
    startActivity(intent);
    

    Now what will happen? System will search for activities with com.yourapp.SOME_ACTION action and if it finds one (in current scenario, it will be activity you have created with com.yourapp.SOME_ACTION in your app), it will start your app (if it is not already started) and will open the activity in your app.

    See, now I can enter into your app by using Activity with com.yourapp.SOME_ACTION. Same thing happens in case of other components.