Vektor88
Vektor88

Reputation: 4920

Android Shell commands execution at boot

In an Android app I'm trying to develop the app runs some shell commands at boot running commands through two functions inside a Receiver onReceive() method , but I have two issues:

  1. The first function executes three separated commands with three calls of executeCommand(), but since in the code of my executeCommand() function is included Process.waitFor(), something in the receiver times out and doesn't always execute all the commands.
  2. The second function commands should execute after the three previous shell commands are executed and return a result, and this doesn't happen. If I remove the Process.waitFor() all the commands are executed, but since the first commands haven't returned a result yet, they act wrong.

Is there a way to extend wait time? Running one only succession of commands instead of three separated commands would reduce the total time of Process.waitFor() ?

Upvotes: 0

Views: 748

Answers (1)

323go
323go

Reputation: 14274

The BroadcastReceiver documentation specifically advises against executing long-running commands on the main-thread of the onReceive() invocation. A better solution would be to create an IntentService to handle the shell commands and execute them in order. This won't block the BroadcastReceiver and should even increase boot speed.

Upvotes: 2

Related Questions