Two launchers for a single activity

2019-01-22 21:03发布

问题:

Is it possible to have multiple app icons which start the same Activity with different intent extras ?

回答1:

There is no way to provide intent extras when launching the activity (via the Launcher).

However, what you can do is use <activity-alias> tags that define additional app icons that will launch the same (target) activity.

EDIT: Add example:

This example shows a real activity call MyRealActivity and an alias called Blahblah. Both have intent-filters that will make them appear on the list of available apps. They have different labels and different icons so that they will look like 2 different apps to the user. However, they both launch the same activity. Please note that there is no java class for .Blahblah, that is just a placeholder and must be unique.

    <activity
            android:name=".MyRealActivity"
            android:label="@string/header_application"
            android:icon="@drawable/icon_myapp">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <activity-alias
            android:targetActivity=".MyRealActivity"
            android:name=".Blahblah"
            android:label="@string/header_blahblah"
            android:icon="@drawable/icon_blahblah">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>


回答2:

I am not sure why you want it. But you can create shortcut on homeScreen which opens the sameApp with different extras.

Have a look at this answer. and this