I am trying to start Firebase jobdispatcher asynchronously using RxJava2.
@Override
public boolean onStartJob(JobParameters job) {
Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
startMethod();
}
}).subscribeOn(mSchedulerProvider.io())
.observeOn(mSchedulerProvider.mainThread())
.subscribeWith(new DisposableCompletableObserver() {
@Override
public void onComplete() {
LOG.debug("onComplete");
onStopJob(job);
}
@Override
public void onError(Throwable e) {
}
});
return true;
}
@Override
public boolean onStopJob(JobParameters job) {
LOG.debug("stop job");
return true;
}
When i added subscribeOn(mSchedulerProvider.io())
line the startMethod()
doesn't start, if I delete this line the startMethod()
starts in Main thread.