Activity.finishAffinity() vs Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK

前端 未结 4 499
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 11:09

In Android, if you want to clear your current Activity stack and launch a new Activity (for example, logging out of the app and launching a log in

相关标签:
4条回答
  • 2021-01-01 11:36

    If API >= 21, you can use the command of:

    finishAndRemoveTask ();

    Finishes all activities in this task and removes it from the recent tasks list.

    https://developer.android.com/reference/android/app/ActivityManager.AppTask.html

    0 讨论(0)
  • 2021-01-01 11:38

    You should use intent flags for that.

    What if you have a large stack of activities, will you call from each one to finish them all?

    Its much better and easier to just call a Intent.

    Hope this helps.

    0 讨论(0)
  • 2021-01-01 11:40

    Functionally, there's no difference, but testing this out on GenyMotion there appears to be a slight visual difference. See web cast: https://drive.google.com/file/d/0B8Y77sY7Y2CGRS02c3UyNjd2MGs/view?usp=sharing

    You would need to try that on a range of devices to see how consistent it is.

    Subjectively, I would say go with the finishAffinity() because it's more explicit. However, if you have to support < SDK 16 you don't really have a choice.

    0 讨论(0)
  • 2021-01-01 11:42

    Try this

    Intent.FLAG_ACTIVITY_CLEAR_TOP
    

    it clears the stack of previous activities

    0 讨论(0)
提交回复
热议问题