rx-java2

RxJava2 observable take throws UndeliverableException

放肆的年华 提交于 2019-11-28 17:13:27
As I understand RxJava2 values.take(1) creates another Observable that contains only one element from the original Observable. Which MUST NOT throw an exception as it is filtered out by the effect of take(1) as it's happened second. as in the following code snippet Observable<Integer> values = Observable.create(o -> { o.onNext(1); o.onError(new Exception("Oops")); }); values.take(1) .subscribe( System.out::println, e -> System.out.println("Error: " + e.getMessage()), () -> System.out.println("Completed") ); Output 1 Completed io.reactivex.exceptions.UndeliverableException: java.lang.Exception:

The result of subscribe is not used

自古美人都是妖i 提交于 2019-11-28 15:37:07
I've upgraded to Android Studio 3.1 today, which seems to have added a few more lint checks. One of these lint checks is for one-shot RxJava2 subscribe() calls that are not stored in a variable. For example, getting a list of all players from my Room database: Single.just(db) .subscribeOn(Schedulers.io()) .subscribe(db -> db.playerDao().getAll()); Results in a big yellow block and this tooltip: The result of subscribe is not used What is the best practice for one-shot Rx calls like this? Should I keep hold of the Disposable and dispose() on complete? Or should I just @SuppressLint and move on?

Flowable concatMapSingle without prefetch to ignore clicks until processing finishes

房东的猫 提交于 2019-11-28 14:49:01
I want to handle clicks in such a way that they are ignored as long as I'm doing processing of some click that occurred. I thought I could do it by utilizing the backpressure, like this: private val clicks = PublishProcessor.create<Unit>() // ... clicks .onBackpressureDrop() .concatMapSingle(::handleClick, 0) But this throws an error, because there's a requirement that concatMapSingle needs to prefetch at least one item, which makes it queue the click and process it immediately after I'm done processing, which is not what I want. I want to process the click only if there is no processing

What is the difference between Observable, Completable and Single in RxJava

送分小仙女□ 提交于 2019-11-28 13:41:34
问题 Can anyone please explain the difference between Observable, Completable and Single in RxJava with clear examples? In which scenario we use one over the others? 回答1: Observable is the generic ReactiveX building block, of event source that emits values over time. (and thus exists in every language ReactiveX extended to) in short Observable events are: onNext* (onCompleted | onError)? /(* zero or more ? - zero or 1) Single and Completable are new types introduced exclusively at RxJava that

multiple api request using retrofit and rx java

拟墨画扇 提交于 2019-11-28 09:29:06
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 think this is not a feasible approach. I know little bit about RX JAVA ,but I only know how to make one

Android Dagger2 + OkHttp + Retrofit dependency cycle error

北城以北 提交于 2019-11-28 08:26:56
Hey there I am using Dagger2 , Retrofit and OkHttp and I am facing dependency cycle issue. When providing OkHttp : @Provides @ApplicationScope OkHttpClient provideOkHttpClient(TokenAuthenticator auth,Dispatcher dispatcher){ return new OkHttpClient.Builder() .connectTimeout(Constants.CONNECT_TIMEOUT, TimeUnit.SECONDS) .readTimeout(Constants.READ_TIMEOUT,TimeUnit.SECONDS) .writeTimeout(Constants.WRITE_TIMEOUT,TimeUnit.SECONDS) .authenticator(auth) .dispatcher(dispatcher) .build(); } When providing Retrofit : @Provides @ApplicationScope Retrofit provideRetrofit(Resources resources,Gson gson,

RxTextView.textChanges with setText on Edittext

可紊 提交于 2019-11-28 04:37:31
问题 RxTextView.textChanges(editText) .map(CharSequence::toString) .debounce(200, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe(input -> { output = //...do something with input editText.setText(ouput) })); When I setText(output) it goes in loop. To set the text I first need to remove listener and then set listener again. How can I do this using RxJava ? 回答1: When I setText(output) it goes in loop. To set the text I first need to remove listener and then set listener

RxAndroid and Retrofit: Unable to create call adapter for io.reactivex.Observable<retrofit2.Response<okhttp3.ResponseBody>>

孤街浪徒 提交于 2019-11-28 03:10:51
问题 I am trying use rxJava, rxAndroid, Retrofit2, and OkHTTP3 to download a file from a URL endpoint. My code is unable to create the call adapter for an "Observable< retrofit2.Response< okhttp3.ResponseBody>>". These methods are new to me so I believe I'm missing an important concept here. Any direction or points is greatly appreciated. FATAL EXCEPTION: main Process: com.example.khe11e.rxdownloadfile, PID: 14130 java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex

When to use RxJava in Android and when to use LiveData from Android Architectural Components?

放肆的年华 提交于 2019-11-28 02:38:30
I am not getting the reason to use RxJava in Android and LiveData from Android Architectural Components.It would be really helpful if the usecases and differences between the both are explained along with sample example in the form of code which explains the differences between the both. Android LiveData is a variant of the original observer pattern, with the addition of active/inactive transitions. As such, it is very restrictive in its scope. Using the example described in Android LiveData , a class is created to monitor location data, and register and unregister based on application state.

What is the difference between RxJava 2 Cancellable and Disposable?

不羁岁月 提交于 2019-11-28 00:41:27
I want to create an Observable from view click listener using RxJava 2. I started from the simplest implementation (I don't use lambdas here to show you different types in this method): Observable<View> viewObservable = Observable.create(new ObservableOnSubscribe<View>() { @Override public void subscribe(@NonNull ObservableEmitter<View> e) throws Exception { mNewWordView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View value) { if (!e.isDisposed()) { e.onNext(value); } } }); } }); Then I thought about the way to set onClickListener to null if it is not needed