launch activities from different package

Solution 1:

I am assuming that by "packages" you mean applications.

We have: - ApplicationA with FirstActivity - ApplicationB with SecondActivity

If, in the ApplicationB's AndroidManifest.xml file, in the declaration of SecondActivity you add an intent filter such as:

<activity android:name=".SecondActivity">
  <intent-filter>
    <action android:name="applicationB.intent.action.Launch" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

You can create an Intent to launch this SecondActivity from the FirstActivity with:

Intent intent = new Intent("applicationB.intent.action.Launch");
startActivity(intent);

What this all means is:

  • The SecondActivity has a filter for the intent action of "applicationB.intent.action.Launch"
  • When you create an intent with that action and call 'startActivity' the system will find the activity (if any) that responds to it

The documentation for this is at: https://developer.android.com/reference/android/content/Intent.html

Solution 2:

I had the same problem and the solution was another level in the root of your package name.

If you have two packages "com.first...." and "com.second...", and the manifest is referencing "com.first". Then you can refactor both packages in order to reuse the first part. For instance, "com.package.first" and "com.package.second". Then your manifest has to be also updated

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

    <activity android:name=".first.FirstPackageActivity" android:label="FirstPackageActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".second.SecondPackageActivity" android:label="SecondPackageActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

Your java code can create an intent and start the activity in the usual way:

Intent intent = new Intent(this,ActivityClassName.class);
startActivity(intent);

Solution 3:

If the package you mentioned here is same to application,I think the answer in the question Android: Starting An Activity For A Different Third Party App is simpler。With the first answer to that question, you don't need to make any modification to your second application.