Reputation: 4283
I have app A and app B, both APK are generated with the same code base. App B is generated with a different flavor than app A, hence they have have different applicationId.
From app A, I'd like to start Activity1 in app B. Here is the code I'm using:
Intent intent=new Intent();
intent.setComponent(new ComponentName("com.packagename.appb", "com.packagename.appb.Activity1"));
startActivity(intent);
I'm getting the exception
ActivityNotFoundException: Unable to find explicit activity class {com.packagename.appb/com.packagename.appb.Activity1}; have you declared this activity in your AndroidManifest.xml?
But Activity1 is already declared in the manifest because it's an activity also available in app A
What should I do ?
Upvotes: 1
Views: 97
Reputation: 4470
You could use following approach if it fits. Create launcher intent:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.packagename.appb");
Put some data inside that Intent
check on MainActivity onStart
method, if data is there move to desired Activity
and finally remove data from Intent
. For example:
intent.putExtra("activityB", true);
startActivity(intent);
Inside B app MainActivity
:
@Override
protected void onStart() {
super.onStart();
Intent intent = getIntent();
boolean shouldStartB = intent.getBooleanExtra("activityB", false);
if(shouldStartB) {
//start new Activity
intent.removeExtra("activityB"); //Don't forget to remove extra to prevent bug
}
}
Upvotes: 1
Reputation: 119
you should use the other app packageName/ class directly. for example:
Intent intent = new Intent("com.example.app");
You'd probably want to put a try/catch around for a ActivityNotFoundException for when the application is not installed
Upvotes: 0