Nick Friskel
Nick Friskel

Reputation: 2437

Correct way to restart activity after phone call ends

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

Upvotes: 0

Views: 91

Answers (1)

Akshay Panchal
Akshay Panchal

Reputation: 695

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

Upvotes: 2

Related Questions