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.