美文网首页
Android彻底关闭进程的方法

Android彻底关闭进程的方法

作者: aimaile | 来源:发表于2017-03-31 17:03 被阅读0次

    在变态测试下会遇到各种各样的奇葩问题,太烧脑了。彻底关闭程序会解决很多问题,我喜欢用前两种。

    第一种方法:

    android.os.Process.killProcess(android.os.Process.myPid());

    第二种方法:在onDestroy函数中加入代码

    System.exit(0);

    第三种方法:

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);manager.killBackgroundProcesses(package);

    第四种方法:

    manager.restartPackage(package);

    第五种方法:

    Intent MyIntent = new Intent(Intent.ACTION_MAIN);MyIntent.addCategory(Intent.CATEGORY_HOME);startActivity(MyIntent);finish();

    相关文章

      网友评论

          本文标题:Android彻底关闭进程的方法

          本文链接:https://www.haomeiwen.com/subject/snuvottx.html