简体   繁体   中英

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". 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,

<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...

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. 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).

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. Then in LauncherActivity you can jump to other:

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 :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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