title: Recovery Reboot with Commands
body: <p>I don't understand why Android does not reboot automatically when the following code is running. In order to fix this, I added System.exit(0); and it works, but why not without this?
  I don't think that System.exit(0); is the best way to fix it.
  Thanks in advance!</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec("su");
  OutputStream os = p.getOutputStream();
  os.write("mkdir -p /cache/recovery/\n".getBytes());
  os.write("echo 'boot-recovery' &gt;/cache/recovery/command\n".getBytes());
  
  os.write("echo '--wipe_cache' &gt;&gt; /cache/recovery/command\n".getBytes());
  
  // Trigger the reboot
  os.write("echo 'reboot' &gt;&gt; /cache/recovery/command\n".getBytes());
  os.write("reboot recovery".getBytes());
  os.flush();
  
  // If I add System.exit(0); it works, but why not without this?
  </code></pre>