views:

45

answers:

2

I have an application with two activities and I'd like to be able to have two icons appear in the launcher, each launching the respective activity within the app.

Specifically, I want one icon to launch my main app, and another icon to launch my settings activity. Is this possible?

Here is what I've tried so far:

    <activity android:label="MyApp" android:name=".MyApp">
        <intent-filter>
            <action android:name=".MyApp"/>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>


    <activity android:label="Settings" android:name=".Settings">
        <intent-filter>
            <action android:name=".Settings"/>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

This creates two launcher icons, but they both run my main app instead of the second icon running my settings app. I've tried just having the launcher category but then I don't get an icon so it looks like I need the main action as well.

Is this the right approach or should I be declaring two applications in the manifest instead?

+1  A: 

What you need to do is have your settings activity launch in another task. You can do this by specifying its task affinity. This is done with the attribute android:taskAffinity. By default all activities share the same task affinity that defaults to main package specified in the manifest. On your settings activity you can specify android:taskAffinity="your.own.package.SettingsTask" to have the settings activity launch in its own task.

Extra documentation.

Qberticus
Great answer, this works perfectly. Thanks!
afonseca
A: 

You're definitely going in the right direction. This is what I have (truncated, because I have all of my activities in the list while I'm devving for fast access):

<activity android:name=".DeckDrill"
          android:label="DeckDrill">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity android:name=".DeckList"
          android:label="DeckList">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

I think what may be happening is interference from your action elements which specify the name of your class. I'm pretty sure that actions and categories need to refer to constants. I don't know how that would result in what you're seeing, but you could try removing them. Other than that, you pretty much have what I have.

treed