0

Both of these methods work, but i'm not sure which would be the best code to use so that it works every time for API 17-25. My app relies on the activity opening after the call ends which I do through a PhoneStateListener.

I have seen both ways recommended, sorry if this is a bad question!

Intent restart = mContext.getPackageManager().
            getLaunchIntentForPackage(mContext.getPackageName());
    restart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    restart.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mContext.startActivity(restart);

or

    Intent intent = new Intent(mContext, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    mContext.startActivity(intent);
Nick Friskel
  • 2,369
  • 2
  • 20
  • 33

1 Answers1

2

You should use recreate() method of Activity class to restart Activity instead of this 2 methods

Akshay Panchal
  • 695
  • 5
  • 15