0

我很困惑。

我有两个来自不同包的活动,比如说“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>

...这不起作用(它给出了“未找到启动器活动”错误)。而且我无法将动作重命名为...

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

...因为那样我就很难引用此活动(请注意,在整个项目中,我一直在使用“com.exampletwo.b”作为我的意图)。

有没有办法让启动器工作,最好不用重命名?

我想我可以通过创建一个虚拟启动器活动来完成这个工作,但是有没有更简单的方法来解决这个问题?

4

1 回答 1

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

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

于 2013-05-02T20:54:25.733 回答