除了 android.os.Process.killProcess 和 Sytem.exit(0) 之外,还有什么方法可以终止我的应用程序?
我的应用程序有问题。当用户单击“退出”时,我真的需要杀死它。我已经尝试了问题标题中列出的两种方法,问题是:我有一个持久(前台)服务正在执行工作,因此我的应用程序有一个托盘图标。当用户通过此图标切换到我的应用程序然后按“退出”时 - 该应用程序被终止,但 Android 立即重新启动它。如果用户使用任何其他方法(不是服务图标)切换回应用程序 - 应用程序在退出时不会重新启动。
那么,可靠的查杀应用程序的方法是什么呢?
PS 应用程序中始终只有一项活动(如果该活动很重要的话)。
I have a problem with my app. I really need to kill it when user clicks "Exit". I've tried both methods listed in the question header, and here's the problem: I have a persistent (foreground) service performing work, so there is a tray icon for my app. When user switches to my app via this icon and then presses "Exit" - the app is kill, but Android immediately restarts it. If the users switches back to the app using any other method (not the service icon) - application is not restarted upon exit.
So, what is the reliable way of killing application?
P. S. There's always only one activity in the application, if that is of any importance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于只有一个
Activity
,我选择finish()
。for only one
Activity
, I choosefinish()
.您可以使用以下意图退出您的活动
,并在调用此意图之前调用 finish() 。
You can use following intent to exit from your activity
and Call finish() before you call this intent.
我已经找到了解决我的问题的方法。如果我使用
moveTaskToBack(true);
将活动移动到后台,然后终止该进程,则它不会重新启动。I have found the solution to my problem. If I move my activity to background with
moveTaskToBack(true);
and then kill the process it is not restarted.