问题描述
我有两个活动,一个应用程序,我想能有两个图标出现在发射器,每个发射程序中的各自的活动。
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?
推荐答案
您需要做的是有你的设置,活动推出的另一项任务。您可以通过指定任务的亲和力做到这一点。这是通过属性安卓taskAffinity
。默认情况下所有活动共享默认主包清单中指定相同的任务亲和力。在你设置的活动,你可以指定安卓taskAffinity =your.own.package.SettingsTask
有设置活动推出了自己的任务。
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.
这篇关于我如何获得多个图标来启动不同的活动在一个应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!