When I switch from running the observeOn on the Main thread to a newThread, the onNext only runs once.
That only way I can get it to work is to keep it on the Main thread, but then I get that it does too much work on the Main Thread.
Without the setErrorHandler it just crashes (Also, can I use doOnError instead of RxJavaPlugins?)
PS. It works on the emulator fine, but it's on the physical device that the issue comes up.
public void updatePie() {
RxJavaPlugins.setErrorHandler(Functions.<Throwable>emptyConsumer());
Observable<Long> intervalObservable = Observable
.interval(1, TimeUnit.SECONDS)
//.doOnError(Functions.<Throwable>emptyConsumer())
.subscribeOn(Schedulers.io())
.takeWhile(new Predicate<Long>() {
@Override
public boolean test(Long aLong) throws Exception {
if (isMyServiceRunning(MyService.class) == false) {
RxB = false;
}
return RxB;
}
})
.observeOn(Schedulers.newThread());
intervalObservable.subscribe(new io.reactivex.Observer<Long>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Long aLong) {
triple = mService.Time;
entries.set(0, new PieEntry(mService.Time, "kronk"));
entries.set(1, new PieEntry(mService.Time2, "notre dame"));
pie_chart.notifyDataSetChanged();
pie_chart.invalidate();
}
@Override
public void onError(Throwable e) {
Log.d(TAG, "Pie Update " + e.toString());
}
@Override
public void onComplete() {
Log.d(TAG, "Pie Update completed");
}
});
}