1
votes

I have app with 2 launcher icons and 2 different Activities. Manifest file is as like below:

....
    <activity
        android:name=".MyActivity"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:taskAffinity="my.package.com.MyActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.LAUNCHER" /> 
        </intent-filter>
    </activity>

    <activity
        android:name=".MySettings"
        android:label="@string/settings"
        android:icon="@mipmap/ic_launcher"
        android:taskAffinity="my.package.com.MySettings">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
....

I want MyActivity to be default screen to be opened after installing, so i used .category.DEFAULT.

action.MAIN and category.LAUNCHER are to show two separate launcher icons (1 for MyActivity, 1 for MySettings).

Problem: When i open MyActivity, MySettings screen is also gets opened. I want each launcher icon to open its corresponding Activity only. I have used taskAffinity for each Activity to solve problem but it did not work. I think to make taskAffinity work, Activity must be started with flag Intent.FLAG_ACTIVITY_NEW_TASK which i can not in my case (both are launch Activities).

I have also tried to use android:launchMode="singleTask" but it did not work either.

How to make each launcher icon to open only its Activity ?

UPDATE: Sorry, i realized MyActivity does not open MySettings, it seemed so though. MyActivity did not have UI, so it showed blank screen which is similar to MySettings. taskAffinity works correct. I have added android:theme="@android:style/Theme.NoDisplay" to MyActivity to hide UI.

2

2 Answers

1
votes

Just use two different images for your apps to launch.

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MySettings"
        android:label="settings"
        android:icon="@drawable/ic_launcher2"
        android:taskAffinity="my.package.com.MySettings">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
0
votes

I solved that way:

<activity
   android:name="andynaz.android.hyperfcalc.MainActivity"
   android:label="@string/app_name" >
   <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

<activity
   android:name="andynaz.android.hyperfcalc.MainActivity2"
   android:label="@string/app_name"
   android:icon="@mipmap/ic_launcher2">
   <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

I did not use the taskAffinity, but I indicated the fully specified name of Activity classes (other than using 2 different images).