来自不同包的启动器的活动意图 - 过滤器操作名称

时间:2012-11-15 06:56:26

标签: java android android-intent manifest launcher

我迷糊了。

我有两个来自不同包的活动,比方说,“com.exampleone.a”和“com.exampletwo.b”。他们属于同一个项目。

在单一清单xml中,由于效率原因,我选择将“com.exampleone”声明为包,即

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.exampleone"
          ....../>

因此,对于我使用的其他活动的意图过滤器......

<intent-filter>
    <action android:name="com.exampletwo.b" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

所以在我的程序中,当我想去com.exampletwo.b时,我会用...

Intent myIntent = new Intent("com.exampletwo.b");
startActivity(myIntent);

碰巧(是的,生活),我最终决定使用活动“com.exampletwo.b”作为发射器。所以我尝试将它改成发射器......

<intent-filter>
    <action android:name="com.exampletwo.b" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

...这不起作用(它给出了'No Launcher Activity Found'错误)。我不能将行动重命名为......

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

...因为那时我在参与这项活动时遇到了麻烦(请注意,在整个项目中,我一直在使用“com.exampletwo.b”作为我的意图)。

有没有办法让发射器工作,最好不需要重命名?

我想我可能会通过创建虚拟启动器活动来实现这一点,但是有更简单的方法来解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

为什么不从你做活动可以选择其他活动开始。 像LauncherActivity,FromOnePackageAct,FromTwoPackageAct之类的东西。 然后在LauncherActivity中你可以跳转到其他:

public class LauncherActivity...
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = new Intent(this, FromOnePackageAct.class);//here´s the trick
    from.startActivity(intent);
//  from.finish(); this is optional

希望这可以为您提供一个想法: - )