[英]How to keep a process running in background in onStop/onPause
I need to make a keep a command running in background even if the app is in background, but I didn't find any way.即使应用程序在后台,我也需要让命令在后台运行,但我没有找到任何方法。 I'm kind new in android developing, So...
我是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("exit\n");
os.flush();
}
RunAsRoot(anycommand);
public void onPause() {
super.onPause();
}
您可以使用 Service 在后台执行任务: http : //developer.android.com/guide/components/services.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.