1

I have an application A that wants to start an Activity in another application, B, which I don't own and cannot edit.

If B is already running and visible in recent apps, there's no problem in executing the wanted Activity of B using an Intent.

If B isn't running, I use the following code to execute its main Activity first, and then the one I want to execute:

String bPackage = "com.example.applicationb";
PackageManager pm = getPackageManager(this);
Intent main = pm.getLaunchIntentForPackage(bPackage);
Intent wanted = new Intent();
wanted.setPackage(bPackage);
wanted.setComponent(new ComponentName(bPackage,bPackage+".WantedActivity"));
main.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
wanted.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
wanted.setExtras(mPreviouslyCreatedBundle);
startActivity(main);
startActivity(wanted);

The wanted Activity executes, but after some seconds I get an error and it stops working. Am I setting the Intents in a wrong way?

Vektor88
  • 4,841
  • 11
  • 59
  • 111

1 Answers1

0

Make sure u have setted exported="true" for activity you are trying to redirect to another package

Basically my idea is when your second paackage app leave u need :

android.os.process.killprocess(android.os.process.mypid())

and when you launch use flag as start new task :

setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
  • According to manifest, both `main` and `wanted` activities have `exported="true"` – Vektor88 Aug 17 '14 at 11:11
  • startActivity(main); startActivity(wanted); will lead to only one activity to be fornt one at time and whast the erorr can u post here? – KOTIOS Aug 17 '14 at 11:14
  • After some tests I found out that my procedure, same proposed by you, was correct. There's a bug in `B` application and I'm going to report the issue on their GitHub. – Vektor88 Aug 17 '14 at 12:29