如何杀死所有活动的应用程序? [英] How to kill an application with all its activities?

查看:158
本文介绍了如何杀死所有活动的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon">Quitting一个应用程序 - 这是令人难以接受的

我要为用户提供一个选项,退出应用程序,因为我需要删除一些敏感的数据,只要在应用软件需要存储在共享preferences。

I want to offer the user an option to exit the application as I need to delete some sensitive data, which is stored in the SharedPreferences as long as the application needs it.

当用户想退出,在共享preferences密码应被消灭,当然还有应用程序的所有活动应关闭(这是没有意义的,而不已知的密码运行它们 - 他们会崩溃)。

As soon as the user wants to exit, the password in the SharedPreferences should be wiped and of course all activities of the application should be closed (it makes no sense to run them without the known password - they would crash).

我怎么能这样做?

System.exit(0)完成()只退出当前的活动 - 无用的。我知道有一个任务管理器应用程序。一个是如何做的呢?它能够杀死整个应用程序...

System.exit(0) and finish() only exit the current activity - useless. I know there is a taskmanager app. How is that one doing it? It's able to kill the whole application...

推荐答案

在使用完成方法,它不关闭整个过程中,它工作在后台。

When you use the finish method, it is not close the complete process, it is working in background.

请使用code的主要活动(请不要在每个活动或子活动中使用):

Please use this code in Main Activity (Please don't use in every activities or sub Activities):

@Override
public void onBackPressed() {

    android.os.Process.killProcess(android.os.Process.myPid());
    // This above line close correctly
}

这篇关于如何杀死所有活动的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆