简体   繁体   English

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

[英]Activity Intent-Filter Action Name for Launcher from Different Package

I'm befuddled. 我很迷惑。

I have two activities from different package, let's say, "com.exampleone.a" and "com.exampletwo.b". 我有两个来自不同软件包的活动,比方说“ com.exampleone.a”和“ com.exampletwo.b”。 They are under the same project. 他们在同一个项目下。

In the single manifest xml, due to efficiency reasons, I had chosen to declare "com.exampleone" as the package, ie, 在单清单xml中,由于效率原因,我选择将“ com.exampleone”声明为包,即

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

As such, for the intent-filter on the other activity i use... 因此,对于其他活动的意图过滤器,我使用...

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

So in my program, when I want to go to com.exampletwo.b, I'd use... 因此,在我的程序中,当我想转到com.exampletwo.b时,我将使用...

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

As it happens (yeah, life), I eventually decided I had to use activity "com.exampletwo.b" as the launcher. 碰巧发生了(是的,生命),我最终决定必须使用活动“ com.exampletwo.b”作为启动器。 So I tried doing changing it into a launcher... 所以,我想这样做改变成发射...

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

...which doesn't work (it gives the 'No Launcher Activity Found' error). ...不起作用(显示“未找到启动器活动”错误)。 And I can't rename the action as... 而且我不能将操作重命名为...

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

...because then I'd have trouble referring to this activity (note that throughout the project I've been using "com.exampletwo.b" for my intents). ...因为那样的话我会遇到麻烦(请注意,在整个项目中,我一直在使用“ com.exampletwo.b”作为我的意图)。

Is there a way that I can get the launcher working, preferably without having to rename anything? 有没有一种方法可以使启动器正常工作,而不必重命名?

I figured I might get this working by creating a dummy launcher activity, but is there an easier way of working this out? 我想我可以通过创建一个虚拟启动器活动来使它正常工作,但是有没有更简单的方法来解决这个问题?

Why just don't make an activity from you can choose other activities to start. 为什么只是不进行活动,您可以选择其他活动来开始。 Something like LauncherActivity, FromOnePackageAct,FromTwoPackageAct. 诸如LauncherActivity,FromOnePackageAct,FromTwoPackageAct之类的东西。 Then in LauncherActivity you can jump to other: 然后,在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

Hope this can provide you an idea :-) 希望这可以为您提供一个想法:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM