0

I have two applications, A and B. In app A I've added a button which opens app B. When the button is clicked I want to open App B if it's not already running, otherwise I want to bring the app to the front.

This is the code I use:

Intent intent = getPackageManager()
            .getLaunchIntentForPackage(
            "com.myapp.something");
if (intent != null) {
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

The code seems to work, but the problem is that if I open app B from app A (using this code) and then click directly the icon of App B, I get two instances of the app, which is undesired.

How can I open the app, as the code does, but also get the same instance even if the app's icon is clicked?

Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48
SuperFrog
  • 7,631
  • 9
  • 51
  • 81

1 Answers1

0

Add Intent.FLAG_ACTIVITY_CLEAR_TOP

Carnal
  • 21,744
  • 6
  • 60
  • 75