如何在onStop/onPause中保持进程在后台运行



即使应用程序在后台,我也需要制作一个保持后台运行的命令,但我没有找到任何方法。我是一个新的android开发,所以…

public void RunAsRoot(String[] cmds) throws IOException {
    Process p = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(p.getOutputStream());
    for (String tmpCmd : cmds) {
        os.writeBytes(tmpCmd + "n");
    }
    os.writeBytes("exitn");
    os.flush();
}
RunAsRoot(anycommand);
public void onPause() {
   super.onPause(); 
}

您可以使用服务在后台执行任务:http://developer.android.com/guide/components/services.html

最新更新