Restarting Android app programmatically

前端 未结 9 2005
独厮守ぢ
独厮守ぢ 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条回答
  •  -上瘾入骨i
    2021-02-03 12:39

    Once you add this FLAGSto the intent

    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    

    and call startActivity(), it will clear all the other activities including the one you call this from, so calling finish() after startActivity() will close the started activity.

    Basically, remove getActivity().finish().

提交回复
热议问题