Launch Activities from Different Package

launch activities from different package

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

Launching Activities via package names

I figured out a method that worked for me, though Brandon's could possibly work on another solution. Here is my solution:

Intent intent = new Intent("com.REDACTED.auto.diagnostics.dealer.MAIN");
intent.setClassName("com.REDACTED.auto.diagnostics",
"com.REDACTED.auto.diagnostics.dealer.MainActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Context c = InstrumentationRegistry.getContext();
c.startActivity(intent);

This possibly does the same thing that Brandon's solution does, however less abstracted.

How do I launch a specific (explicit) activity of another app

Try this:

Intent intent = new Intent();
intent.setClassName("com.pas.webcam.pro", "com.pas.webcam.Rolling");
startActivity(intent);

Since you refer to the app as "IP webcam pro", I'm assuming the package name is "com.pas.webcam.pro" (found by Internet research).

Unable to start activity from the different package [Android]

Its possible :) and your launch is correct, so it must be setup that is something wrong with. To be exact you should start activity2 from activity1 why you ask well the manifest is the answer I say. You see the package refered to in the manifest is where your main activity should reside.



Related Topics



Leave a reply



Submit