0

I´m trying to make an application where the user can call his friend, but to avoid the user to use the native call intent from android, I start the native intent and with a broadcast receiver I resume my previous application to a screen where it simulates a call screen with hang up button, speaker button and others...

however, my broadcast receiver is located in another APK (for architectural reasons)... how can I resume my previous APK in its state? Actually i was trying to use this code, but it does not resume my activity, it creates a new one, losing the old data

PackageManager packageManager = context.getPackageManager();
Intent i= packageManager.getLaunchIntentForPackage("path.to.package");
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
context.startActivity(i);
jguilhermeam
  • 121
  • 1
  • 1
  • 10

2 Answers2

1

I think you need might need your activity to be a Single Instace, so instead of creating a new one each time, it will try to reuse an already launched activity as long as you have not killed it yet, you need to read more about single instance or singletask activity depending on what fits your problem, take a look at this question, hopefully it will help...

Android singleTask or singleInstance launch mode?

Regards!

Community
  • 1
  • 1
Martin Cazares
  • 13,637
  • 10
  • 47
  • 54
  • how can I make my activity to be single instance @martin-cazares ? – jguilhermeam Jun 19 '13 at 19:53
  • In the AndroidManifest where you declare the activity, the XML tag accepts this property: android:launchMode=["multiple" | "singleTop" | "singleTask" | "singleInstance"] All you have to do is to set it as singleInstance – Martin Cazares Jun 19 '13 at 20:34
1

I solved it... I changed my flag to FLAG_ACTIVITY_SINGLE_TOP

Final code:

PackageManager packageManager = context.getPackageManager();
Intent i= packageManager.getLaunchIntentForPackage("path.to.package");
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(i);
jguilhermeam
  • 121
  • 1
  • 1
  • 10