I have a background service that lasts approximately 5 minutes and executes X methods every X time each, it is necessary that those times are fulfilled and go consecutive.
The problem is that Android 7 kills the service by "turning off the screen".
Can I do this with a JobScheduler? (the service has timers inside), or should you use a foreground service?
Example of my service:
public class MyServide extends Service {
class MyBinder extends Binder {
MyServide getService() {
return MyServide.this;
}
}
public IBinder onBind(final Intent intent) {
if (intent != null) {
Observable.timer(randomTime), TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aLong -> {
//random code
});
}
return MyBinder;
}
}