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

◇◆丶佛笑我妖孽 提交于 2019-11-30 10:55:23

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.

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

Developer_vaibhav

Try this

Intent.FLAG_ACTIVITY_CLEAR_TOP

it clears the stack of previous activities

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!