【问题标题】:How to keep a process running in background in onStop/onPause如何在 onStop/onPause 中保持进程在后台运行
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 2021-06-24
    • 1970-01-01
    相关资源
    最近更新 更多