How to exit the Android application completely from any Activity
Have to call System.exit(0) but that was not recommend.
Here is a good discussion about this topic in Stackoverflow.
Close all the Android ativities
There is no good way to close all the ativities except by calling finish().
One solution is to add a listener to a root Activity and other acivities extend that root one. Then add finish() into the callback of the listener.
Maybe we can add Intent flag of FLAG_ACTIVITY_NEW_TASK, FLAG_ACTIVITY_CLEAR_TOP orFLAG_ACTIVITY_CLEAR_TASK(start from Android SDK 10) when calling startActivity(). You can see the detailhere.
本文讨论了如何从任何活动(Activity)中彻底关闭Android应用程序的方法。推荐的做法不是使用System.exit(0),而是通过调用finish()来关闭所有活动。一种解决方案是在根Activity中添加一个监听器,并让其他活动继承该根Activity,然后在监听器的回调中添加finish()来实现。此外,还可以考虑在启动新的活动时设置特定的Intent标志。
1489

被折叠的 条评论
为什么被折叠?



