Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two launchers for a single activity

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

like image 826
sdabet Avatar asked Jun 28 '12 07:06

sdabet


People also ask

Can we have two launcher activities?

On latest Android versions - If there are more than one launcher activities and if we don't put this category tag then the activity which is mentioned first in the Android manifest file will get launched as start-up activity.

Can I have multiple launchers android?

Yes, You can have more than one launcher activity in your application. This will not create any kind of compile-time or run time error. You will find two launcher logos of your application in your device can launch different activities as we defined in manifest.

What is a launcher activity?

It means you didn't specify an Activity for Android to launch as the default when the app opens from the launcher. You have to add an Intent Filter in the Manifest for the Activity you would like to act as the default when the app is being launched.

What is activity alias Android?

description: An alias for an activity, named by the targetActivity attribute. The target must be in the same application as the alias and it must be declared before the alias in the manifest. The alias presents the target activity as an independent entity.


1 Answers

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>
like image 189
David Wasser Avatar answered Sep 24 '22 02:09

David Wasser