Restarting Android app programmatically

前端 未结 9 2006
独厮守ぢ
独厮守ぢ 2021-02-03 12:14

This is a follow up question to this question:

Force application to restart on first activity

I am trying to restart my application from a fragment like that:

9条回答
  •  日久生厌
    2021-02-03 12:34

    try using below lines:

    Intent i = getBaseContext().getPackageManager()
                    .getLaunchIntentForPackage(getBaseContext().getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
    ActivityCompat.finishAfterTransition(YourCurrentActivity.this);
    

    ActivityCompat.finishAfterTransition(YourCurrentActivity.this); this line clear the instance after creating another activity

提交回复
热议问题