【发布时间】:2015-11-06 08:00:58
【问题描述】:
即使应用程序在后台,我也需要让命令在后台运行,但我没有找到任何方法。我是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();
}
【问题讨论】:
-
您可以使用 Thread 或其他服务。如果您想在应用程序终止后继续后台进程,那么我更喜欢您使用服务。
-
你能告诉我一个来源或一个链接,要遵循的代码。我只需要起点。
-
tutorialspoint.com/android/android_services.htm 看看这个链接。它让您更好地了解服务
-
我会的,谢谢。
标签: java android process background onpause