I wrote simple android service and I would like to execute ADB command in background once per second.
Function startInterval is executing once in start service method onStartCommand.
When activity is visible, command is executing and everything works good but when i close activity in service response I get only log message.
Probably Runtime.getRuntime function works correctly only with activity process running.
Is there any solutions to execute command in service with closed activity?
Function startInterval is executing once in start service method onStartCommand.
Java:
public void startInterval(){
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
Log.d("state", "before click");
Runtime.getRuntime().exec("input tap 100 100");
Log.d("state", "after click");
} catch (Exception e){
System.out.print(e);
}
}
}, 0, 1, TimeUnit.SECONDS);
}
When activity is visible, command is executing and everything works good but when i close activity in service response I get only log message.
Probably Runtime.getRuntime function works correctly only with activity process running.
Is there any solutions to execute command in service with closed activity?