3

killprocess method does kill the processes but why the processes restart again and what is suppose to do for not restarting the process again. Here goes my code.

ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> services = manager.getRunningAppProcesses();
for (RunningAppProcessInfo info : services) {   
    int service1name = info.pid;
    android.os.Process.killProcess(service1name);
}

Thanks for your concern.

Axe
  • 6,285
  • 3
  • 31
  • 38
kamal_tech_view
  • 4,235
  • 4
  • 28
  • 49

3 Answers3

0

Actually the process kill through the killProcess restart the process because android os assume that the process has been shutdown due to crashing and restart it again. What I find is we can use the higher priority am (activity manager) to kill the process. Example can be find here :

try {

                Log.d("Application all process", "killing++");
            String killCommand = 
                        "am force-stop com.nil.android.ssd";
                runAsRoot(new String[]{killCommand},true);
            } catch (Exception e) {
                e.printStackTrace();
            }


    public static void runAsRoot(String[] cmds, boolean shouldExit) {
        try {
            Process p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());
            for (String tmpCmd : cmds) {
                os.writeBytes(tmpCmd + "\n");
            }
            if (shouldExit) {
                os.writeBytes("exit\n");
            }
            os.flush();
        } catch (Exception iOException) {
            iOException.printStackTrace();
        }
    }
kamal_tech_view
  • 4,235
  • 4
  • 28
  • 49
0

Stop All running Activitiy and Service, Otherwise, just use android.os.Process.killProcess(android.os.Process.myPid()); the process will restart

sansecy
  • 26
  • 4
-1

I have faced the similar problem and It got solved with

   this.finishAffinity();

And this is supported from API level 16.

Godugu
  • 1
  • 1