如何保持一个进程在onStop/onPause后台运行
问题描述:
我需要在后台运行一个命令,即使应用程序在后台运行,但我没有找到任何方法。我在Android开发方面的一种新的,所以......如何保持一个进程在onStop/onPause后台运行
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();
}
您可以使用螺纹或其他服务。如果你想在应用程序被杀后继续后台进程,那么我更喜欢你使用服务。 – Madhu
你可以给我看一个源代码或链接,代码如下。我只需要起点。 – MoJo
http://www.tutorialspoint.com/android/android_services.htm检查出这个链接。它给你更好的了解服务 – Madhu