简体   繁体   中英

“MAIN” and “LAUNCHER” are redundant for the launcher activity

Consider the following code:

<activity
    android:name=".activity.SplashScreenAct"
    android:label="Logo">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Are "MAIN" and "LAUNCHER" redundant for specifying an activity to be a launcher activity? Is there any situation that we would use only "MAIN" but not "LAUNCHER"? Is there any situation that we would use only "LAUNCHER" but not "MAIN"? Could there be multiple "LAUNCHER" activities in an application?

Partly answering the question:

MAIN and LAUNCHER are not redundant for specifying an activity to be a launcher activity. Suppose you have two activities in your app. If you want two launchers at the home screen - one launching the first activity while the other launching the second, you will have to keep both MAIN as well as LAUNCHER in the <intent-filter> tag. You skip any of them from one of the activities and you start seeing only one physical launcher icon at your home screen - which launches the other activity.

You keep both MAIN and LAUNCHER in both activities, you can see two physical launcher icons at your home screen. Each launching the related activity.

Little confusing, but this analogy might help you: In a group of people, you'll be the leader, but no one will know about you (MAIN). Everyone will know you, you'll be the face of the group, but not the leader (LAUNCHER).

Are "MAIN" and "LAUNCHER" redundant for specifying an activity to be a launcher activity?

That would be a no, with these differences taken into consideration

android.intent.action.MAIN 

means that the respective activity is the entry point of the application, ie when you launch the application, this activity is created.

From this documentation

category -- Gives additional information about the action to execute, therefore: android.intent.category.LAUNCHER

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

launcher

Logic of the last two questions based on the information above puts these to questions to have "No" as it's respective answers.

Is there any situation that we would use only "LAUNCHER" but not "MAIN"?

Could there be multiple "LAUNCHER" activities in an application?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM