Reputation: 4920
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:
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. 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
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