Skip to content Skip to sidebar Skip to footer

Opening Second Aapp's Specific Activity

I have two applications App1 and App2 I want to open App2's Third activity from App1 and I want to pass some values between applications too. How can I do this.? I have tried this:

Solution 1:

The problem is here

IntentLaunchIntent=   getPackageManager().getLaunchIntentForPackage("com.example.aap2.MainActivity3");

here you have to pass the packagename but you are passing Activity name..that too the above will return the launcher Activity you have set in the manifest file..

For this you need to change your code like this..

Intenti=newIntent();
i.setClassName("com.example.aap2", "com.example.aap2.MainActivity3");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

And set android:export="true" for MainActivity3 in Manifest.

Solution 2:

Use

Intentintent=newIntent();
intent.setComponent(newComponentName("com.example.app2", "com.example.aap2.MainActivity3"));
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Make sure this falg is really need.
startActivity(intent);

Useful resources

  1. Allowing Other Apps to Start Your Activity
  2. Interacting with Other Apps

You need to write Activity declaration into manifest as (for second app)

<activity android:name=".MainActivity3"
        android:label="@string/app_name"
        android:exported="true" >
        // Add intent filter if any. 
</activity>

Solution 3:

Use this only if you don't know the Activity Name and don't pass activity name in it like you did

IntentLaunchIntent=   getPackageManager().getLaunchIntentForPackage("com.example.aap2");

Otherwise just simply try following method, the usual method to open another activity is

Intentintent=newIntent(Intent.ACTION_MAIN);
intent.setComponent(newComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);

Post a Comment for "Opening Second Aapp's Specific Activity"