在AndroidManifest.xml中两项主要活动 [英] Two main activities in AndroidManifest.xml

查看:128
本文介绍了在AndroidManifest.xml中两项主要活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有我的应用程序主要活动。  所以在我的表现,我把

I would like to have to main activities in my app. So in my manifest I put

  <activity
        android:name="mypackage1.MainActivity"
        android:label="@string/title_activity_main"

        <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="mypackage2.MainActivity2"
        android:label="@string/title_activity_main2"
      "
         >
         <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>

两个图标在我的应用程序菜单中创建。但是,当我点击他们每个人的第一个活动MainActivity总是启动。是否有可能有两个主要活动?如果是这样,什么是错的我做了什么? 谢谢

Two icons are created in my apps menu. But when I click on each of them the first activity MainActivity is always launched. Is it possible to have two main activities? If so, what's wrong with what I did? Thanks

推荐答案

LAUNCHER 意图过滤器是什么决定了显示在应用程序的抽屉/发射器。这就是为什么你显示了两个图标。

The LAUNCHER intent filter is what determines what shows up in the app drawer/launcher. That is why you get two icons shown up.

不过,您还可以设置默认意图过滤器,它设置默认的活动为全包。既然你两次设置它,你得到的第一个precedence问题/最新注册。当您删除默认过滤器,你就可以开始无论你在启动点击。

However, you also set the DEFAULT intent filter, which sets the default Activity for the whole package. Since you set it twice, you get the problem of precedence of the first/latest registered. When you remove the DEFAULT filter, you will be able to start whatever you click on in the launcher.

在总之,无论从活动中删除以下行:

In short, remove the following line from both Activities:

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

这篇关于在AndroidManifest.xml中两项主要活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆