android应用立马杀死策略

1.实际开发中遇到的问题:

android.os.Process.killProcess(android.os.Process.myPid());无法根本杀死应用进程,还存在服务没有杀死
2.采用改进方案:
 1 public void killProgress() {
 2         CallServer.getInstance().cancelAll();//取消所有网络请求
 3         Intent startMain = new Intent(Intent.ACTION_MAIN);
 4         startMain.addCategory(Intent.CATEGORY_HOME);
 5         startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 6         startActivity(startMain);
 7         //杀死该应用进程
 8         android.os.Process.killProcess(android.os.Process.myPid());
 9         System.exit(0);
10 }

3.分析:

3~6行可以全部杀死同时也包括service






















原文地址:https://www.cnblogs.com/jeffery336699/p/9288973.html