How do I get multiple icons to launch different activities in one application?

前端 未结 2 590
青春惊慌失措
青春惊慌失措 2020-11-27 03:09

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.

相关标签:
2条回答
  • 2020-11-27 03:40

    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.

    0 讨论(0)
  • 2020-11-27 03:43

    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.

    0 讨论(0)
提交回复
热议问题