O
O
OM12016-10-06 22:19:42
Android
OM1, 2016-10-06 22:19:42

Android: function call on RxJava, how?

Hello!
How to implement a function call in RxJava followed by event handling, i.e. timeout or callback?
For example there is:

public Boolean foo(Boolean p){
return !p;
}

Here's how to execute foo() and handle its "behavior"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Дмитрий Серков, 2016-10-06
@Hutaab

Можно так:

Observable.create(
                new Observable.OnSubscribe<T>() {
                    @Override
                    public void call(Subscriber<? super T> sub) {
                        sub.onNext(okhttp запрос);
                        sub.onCompleted();
                    }
                })
                .map(здесь обрабатывем ответ)
                .timeout(5, TimeUnit.SECONDS) //таймаут
                .retry(3) // попытки
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(результат -> выводим, сохраняем);

T
Tiberal, 2016-10-07
@Tiberal

https://medium.com/yammer-engineering/converting-c...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question