0

In my app i have an Activity and fragment, from fragment on button click im doing an Implicit Intent, opening another app. When another app opens if i do device back press, both the apps are closing. I want my app should resume. Please any guide me what im going wrong. Thanks

im doing intent like this

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.basic");
     if (launchIntent != null) {
         launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         startActivity(launchIntent);
     } else {
        Toast.makeText(getContext(), "Package not found", Toast.LENGTH_SHORT).show();
     }

my Activity onBackPressed

 @Override
 public void onBackPressed() {
       FragmentManager fm = getSupportFragmentManager();
       int backStackEntryCount = fm.getBackStackEntryCount();
       if(backStackEntryCount>1) {
            super.onBackPressed();
        }
 }
Make it Simple
  • 1,832
  • 5
  • 32
  • 57

1 Answers1

0

See when you open up a new Activity this Activity gets stacked over the currently running activity and when you press back then the the New Activity Closes and it restores the previous activity from the Stack.

 Activity A ------opens new activity -----> Activity B 

 Activity A <------on back press----- Activity B 

But when you open a another application from your Application. its like you manually opening a another application. Like what you do normally to manually open another app suppose you are using FB App and now you want to open another say Instagram.

Steps

  1. Minimize the application that is FB

  2. Then open Instagram

  3. Now when you close Instagram it will not resume with Previous FB app

This is what is happening with you code. So you need to use this

 startActivityForResult(intent,101); // then if the user closes the app it will resume to your app

instead of startActivity(intent);

Paul P Joby
  • 713
  • 7
  • 17