2

I want to launch the installed app2 from app1, the simple method is as follow:

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.app2");
startActivity(LaunchIntent);

But I also want to make sure that app2 and app1 are in different task stack:

eg. when I launch app2 from app1 and press home button, then I open the task list, I'll see both app1 and app2 from the list, and both of them can be successfully called back.

The state of the app1 should be what it is just before I call app2 from app1.

What else should I do to achieve this?

tuoniuniu
  • 93
  • 6
  • I tried "intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);", but not as expected. After I call app2 from app1, there is indeed 2 task in the list. But if I close app2, and click app2 in task list, I cannot start it, this is the problem – tuoniuniu Dec 30 '14 at 10:29
  • What do you mean by "cannot start it"? You tap and nothing happens? This is not really possible. – Nuwisam Dec 30 '14 at 10:36
  • Yes, I tap and nothing happens. If I do not close app2, everything is fine. But after I close it, I cannot restart it in the task list – tuoniuniu Dec 30 '14 at 10:41
  • First of all - your question is answered. You use mentioned flag and the second app is starting as intended. Accept some answer here and post another question, preferably with some code of your second app. I do not believe in "nothing happens" scenario, so I guess that the app is starting, but causing some exception and shutting down. We will be glad to help, but to keep things clear - post another question and describe your new problems there. – Nuwisam Dec 30 '14 at 10:44

2 Answers2

0

Try reading this article about launchModes.

And in case someone is lazy, here is what is the most important:

[...] Typically, they're launched into the task that called startActivity() (unless the Intent object contains a FLAG_ACTIVITY_NEW_TASK instruction, in which case a different task is chosen — see the taskAffinity attribute). [...]

Basically it comes to:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.app2");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Nuwisam
  • 830
  • 6
  • 10
0

try with below code

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.app2");
LaunchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(LaunchIntent);
Roll no1
  • 1,315
  • 1
  • 16
  • 23