Search code examples
androidandroid-intent

How to resume an activity from another application?


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);

Solution

  • 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);