rx-android

How to use CompositeDisposable of RxJava 2?

北城以北 提交于 2019-12-20 08:06:29
问题 In RxJava 1, there was CompositeSubscription, but that is not present in RxJava2, There is something CompositeDisposable in rxJava2. How do I use CompositeDisposable or Disposable in RxJava2? 回答1: private final CompositeDisposable disposables = new CompositeDisposable(); // adding an Observable to the disposable disposables.add(sampleObservable() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableObserver<String>() { @Override public void

Retrofit with Rxjava Schedulers.newThread() vs Schedulers.io()

假装没事ソ 提交于 2019-12-18 10:15:02
问题 What are the benefits to use Schedulers.newThread() vs Schedulers.io() in Retrofit network request. I have seen many examples that use io() , but I want to understand why. Example situation: observable.onErrorResumeNext(refreshTokenAndRetry(observable)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread())... vs observable.onErrorResumeNext(refreshTokenAndRetry(observable)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread())... One of the reasons

AsyncTask replacement with RXJava help needed

ぃ、小莉子 提交于 2019-12-18 05:17:11
问题 I am new to Reactive so go easy on me, but I am trying to replace an async task that is currently run on text changes for an auto suggest function. Below is where I am at with my RX: rest.getMemberList(etSearch.getText().toString())//rest interface .subscribeOn(Schedulers.io()) .observeOn(RxAndroidSchedulers.mainThread()) .subscribe(new Action1<List<Member>>() { @Override public void call(List<Member> results) { ListView ResultsListView = (ListView) findViewById(R.id.list); MemberAdapter =

My subscriber's onNext and onComplete functions do not run when I call onNext within my FlowableOnSubscribe class

倖福魔咒の 提交于 2019-12-17 21:04:31
问题 In an Android project that uses RxJava 2, I create a Flowable like this in the onCreate of my initial activity: Flowable.create(new MyFlowableOnSubscribe1(), BackpressureStrategy.BUFFER) .doOnComplete(new MyAction()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new MySubscriber()); The implementation of the FlowableOnSubscribe is: public class MyFlowableOnSubscribe1 implements FlowableOnSubscribe<String> { public static final String TAG = "XX MyFlOnSub1"

multiple api request using retrofit and rx java

雨燕双飞 提交于 2019-12-17 19:03:31
问题 I am new to android and I have a scenario where I want to get get data from multiple api. Let suppose api_a , api_b , api_c , api_d . These api are independent of each other but I want to show data from these api in a mix Recycler View ( horizontal and vertical ). So I want to make these api call in such a manner so that I can get every api data at a time so that i can display in recycler view. I already using retrofit 2 but for that I had to chain them one by one which is very lengthy and I

Stack overflow when using Retrofit rxjava concatWith

谁说胖子不能爱 提交于 2019-12-17 15:44:53
问题 I want to handle pagination in Retrofit using rxjava Observable. I followed the advice from another question. I have more than 100 pages that needs to be fetched, but chain fails around the 20th page and stops any further subscription to the observable with the below log in the logcat 04-04 04:12:11.766 2951-3012/com.example.app I/dalvikvm﹕ threadid=28: stack overflow on call to Ljava/util/concurrent/atomic/AtomicLongFieldUpdater$CASUpdater;.compareAndSet:ZLJJ 04-04 04:12:11.766 2951-3012/com

Retrofit RxAndroid make wrapper for api calls

柔情痞子 提交于 2019-12-14 02:06:18
问题 I wanted to create a wrapper for api calls in retrofit so I can display ProgressDialog at common place & handle common response. I achieved this by creating wrapper like this public static <T> Observable<T> callApiWrapper(final Context context, final boolean shouldShowProgress, final String message, final Observable<T> source) { final ProgressDialog progressDialog = new ProgressDialog(context); if (shouldShowProgress) { if (!TextUtils.isEmpty(message)) progressDialog.setMessage(message); else

RxJava retry based on logic

我的梦境 提交于 2019-12-14 00:21:50
问题 Here is the case, I have API call usign Retrofit that might fail due to network error. If it fails we will show error message with a retry button. When user presses the retry button we need to retry the latest Observable again. Possible Solutions: Retry: Retry should be used before subscribing to the observable and it will immediately resubscribe again if error happens and that is what I don't want, I need to resubscribe only if the user pressed the Retry button. RetryWhen: It Will keep

Merging Observables with feedback, merging Observable with Itself

可紊 提交于 2019-12-13 17:56:16
问题 I need to create Observable, that will collect information from different sources(other Observables), and each source has impact on the event value, but still, the value is built based on previous value(kind of state machine). We have message with int value and operation code: class Message{ Integer value; String operation; public Message(Integer value, String operation) { this.value = value; this.operation = operation; } } And some source of such values, with init value: Observable<Message>

RxJava/Android: Combine result of two dependent Observables

独自空忆成欢 提交于 2019-12-13 12:25:46
问题 I have two Observables . Observable<A> getAObservable() Returns Observable of A Observable<B> getBObservable(A) Returns Observable of 'B'. Here Observable<A> should execute before Observable<B> so that it can pass its result A to getBObservable() method. Now once Observable<B> completes I need to combine the result of these observable and Observable<AB> should returns. Options Tried: Take Observable<A> and apply flatMap on it so that it transform result in B . Now at this point I am not