-2

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...

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(); 
}
MoJo
  • 44
  • 7
  • You can use Thread or else services. If you want to continue the background process even after the app killed then i prefer you to use services . – Madhu Nov 06 '15 at 08:05
  • can you just show me a source or a link, code to follow. I only need the start point. – MoJo Nov 06 '15 at 08:06
  • http://www.tutorialspoint.com/android/android_services.htm check it out this link. it give you better understanding of service – Madhu Nov 06 '15 at 08:09
  • sure I will, thank you. – MoJo Nov 06 '15 at 08:11

1 Answers1

2

You can use a Service to do tasks in the background: http://developer.android.com/guide/components/services.html

Björn Kechel
  • 7,933
  • 3
  • 54
  • 57