2

I have an Android app where I wish to have 2 Activities that can be launched from the app drawer. I've declared both Activities in the AndroidManifest, but it seems like only the 1st one is being launched no matter which app I tap on. The 2nd declaration seems to be ignored, as I don't even get an app crash if I specify an invalid name.

Here's my manifest.

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".Activity1"
        android:label="@string/activity1" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Activity2"
        android:label="@string/activity2">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
user1118764
  • 9,255
  • 18
  • 61
  • 113
  • From this question is looks like the developer was able to support multiple launcher activities by adding an `android:icon` attribute to their activities. Maybe take a look at it and see if there is anything helpful there? http://stackoverflow.com/questions/22804597/handle-same-intent-filter-for-different-activity – Dr. Nitpick Jul 04 '16 at 05:11

2 Answers2

0

I guess you need to specify which activity is the default one by adding the following line to your intent-filter:

<category android:name="android.intent.category.DEFAULT"/>

Try inserting it in the default activity's manifest tag and keep the other one the same.

Talha Mir
  • 1,228
  • 11
  • 19
0

Replace your code with this :-

   <activity
        android:name=".Activity1"
        android:label="@string/activity1" >
    </activity>
    <activity
        android:name=".Activity2"
        android:label="@string/activity2">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  • In this case your Activity2 will load first. Second thing is you cannot provide launcher category for both activities. As soon as you start your app it will launch that activity which will have this <category android:name="android.intent.category.LAUNCHER" />.
Nishant Thapliyal
  • 1,540
  • 17
  • 28