void onRunSchedulerExampleButtonClicked() { sampleObservable() // Run on a background thread .subscribeOn(HandlerScheduler.from(backgroundHandler)) // Be notified on the main thread .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<String>() { @Override public void onCompleted() { Log.d(TAG, "onCompleted()"); } @Override public void onError(Throwable e) { Log.e(TAG, "onError()", e); } @Override public void onNext(String string) { Log.d(TAG, "onNext(" + string + ")"); } }); }
public void onCreate(PlaybackServiceProxy proxy) { mProxy = proxy; //fire up thread and init handler mHandlerThread = new HandlerThread("PlaybackServiceHandler", Process.THREAD_PRIORITY_MORE_FAVORABLE); mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); mHandlerScheduler = HandlerScheduler.from(mHandler); mQueueChangeListener = new PlaybackQueueQueueChangeListener(); mSessionCallback = new MediaSessionCallback(); //tell everyone about ourselves mQueue.setListener(mQueueChangeListener); mSessionHolder.setCallback(mSessionCallback, mHandler); proxy.setSessionToken(mSessionHolder.getSessionToken()); setupLocalRenderer(); mHandler.post(mLoadQueueRunnable); }
public synchronized void start(long delay) { running = true; Timber.d("start(%d) lastEvent=%d", delay, lastEvent.get()); if (handlerThread == null) { handlerThread = new HandlerThread("EventMonitor"); handlerThread.start(); scheduler = HandlerScheduler.from(new Handler(handlerThread.getLooper())); } //TODO check connectivity and fail fast eventSubscription = eventsObservable .subscribeOn(scheduler) .subscribe(Subscribers.from(eventsObserver)); }
void onRunSchedulerExampleButtonClicked() { sampleObservable() // Run on a background thread .subscribeOn(HandlerScheduler.from(backgroundHandler)) // Be notified on the main thread .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<String>() { @Override public void onCompleted() { Log.d(TAG, "onCompleted()"); schedulerTv.setText("onCompleted"); schedulerTv.setClickable(false); } @Override public void onError(Throwable e) { Log.e(TAG, "onError()", e); schedulerTv.setText("onError()"); schedulerTv.setClickable(false); } @Override public void onNext(String string) { Log.d(TAG, "onNext(" + string + ")"); schedulerTv.setText("onNext(" + string + ")"); schedulerTv.setClickable(false); } }); }
@Provides @ArtworkFetcherScope @Named("ObserveOnScheduler") public Scheduler provideObserveOnScheduler() { return HandlerScheduler.from(new Handler(service.getHandlerThread().getLooper())); }
/** * <p> * Apply the subscribeOn/observeOn transformation of {custom_handler}/mainThread * to an observable via compose() * </p> * * <p> * Only apply this to observables that are handling computation tasks in the background. Basically * all non-IO work * </p> * * @param <T> the transformation type * @return the observable post-transform */ public static <T> Observable.Transformer<T, T> applyCustomSchedulers(final Handler subscribeHandler) { return new Observable.Transformer<T, T>() { @Override public Observable<T> call(Observable<T> observable) { return observable.subscribeOn(HandlerScheduler.from(subscribeHandler)) .observeOn(AndroidSchedulers.mainThread()); } }; }
/** * <p> * Apply the subscribeOn/observeOn transformation of computation/mainThread * to an observable via compose() * </p> * * <p> * Only apply this to observables that are handling computation tasks in the background. Basically * all non-IO work * </p> * * @param <T> the transformation type * @return the observable post-transform */ public static <T> Observable.Transformer<T, T> applyCustomSchedulers(final Handler subscribeHandler, final Handler observeHandler) { return new Observable.Transformer<T, T>() { @Override public Observable<T> call(Observable<T> observable) { return observable.subscribeOn(HandlerScheduler.from(subscribeHandler)) .observeOn(HandlerScheduler.from(observeHandler)); } }; }