rx-java2

Using RxJava 2 and Retrofit 2, adapter version issue

萝らか妹 提交于 2019-12-01 19:06:32
问题 I've added a new library module to existing application module in Android Studio. The main difference was adding RxJava 2 and Retrofit 2. After updating build.gradle of new module I started to get next error: Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForBetaNewApiDebug'. com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties File1: C:\Users\Gaket.gradle

BlockingGet block UI thread RxJava 2

丶灬走出姿态 提交于 2019-12-01 16:22:32
问题 I am dealing with the problem. I am trying to call RxJava in the sync manner, however doing that results in blocking the Main thread. Here is my code @Override public Single<SettingsBundle> getSettings() { SettingsBundle settingsModel = mSettingsManager.getSettings(); return Single.just(settingsModel).map(mSettingsMapper); } And here is my sync call @Override public SettingsBundle getSettingsSync() { return getSettings().blockingGet(); } When calling the getSettingsSync the Main thread is

RxJava: upstream never completes when error is swallowed

☆樱花仙子☆ 提交于 2019-12-01 13:04:06
I'm using RxJava to iterate over a list of files, making a network call to upload each file, then collect the files that were successfully uploaded in a list and persist those files in the subscriber on success. This code works, except for when an error occurs. The behavior should be that it logs the error and continues, which it does, except when an error occurs the subscriber's onSuccess lambda never gets called. Is the observer expecting the same number of elements to be emitted as are in the original iterable? How can I skip the errors and have it complete once all items have been iterated

RxJava: upstream never completes when error is swallowed

假装没事ソ 提交于 2019-12-01 10:17:48
问题 I'm using RxJava to iterate over a list of files, making a network call to upload each file, then collect the files that were successfully uploaded in a list and persist those files in the subscriber on success. This code works, except for when an error occurs. The behavior should be that it logs the error and continues, which it does, except when an error occurs the subscriber's onSuccess lambda never gets called. Is the observer expecting the same number of elements to be emitted as are in

When to call dispose and clear on CompositeDisposable

夙愿已清 提交于 2019-12-01 02:27:35
My question can be a duplicate of How to use CompositeDisposable of RxJava 2? But asking to clear one more doubt. According to the accepted answer // Using clear will clear all, but can accept new disposable disposables.clear(); // Using dispose will clear all and set isDisposed = true, so it will not accept any new disposable disposables.dispose(); In my case, I'm using fragments as my views (View layer in MVP) and in some scenarios, I add active fragment to backstack, which actually does not kill the Fragment but only its view. Which means only onDestroyView is called and not the onDestroy .

RxJava 2 / Retrofit 2 - NetworkOnMainThreadException

随声附和 提交于 2019-11-30 22:00:41
I need to perform a request, if my token is expired I need to refresh it and retry the request. This is how I'm trying to do it, at the moment I can refresh the token but it throws me a NetworkOnMainThreadException. It finishes the request,update the token and reaches logs, but that exception its killing me. How can I avoid that? public Observable<Estabelecimento> listarEstabelecimentos() { return Observable.defer(this::getListarEstabelecimentoObservable) .retryWhen(throwableObservable -> throwableObservable.flatMap( throwable -> { if (throwable instanceof UnauthorizedException) { return

Why Does Room Delete Operation(With RxJava) Gives UI Thread Error Even Specifying Different Subcribe Thread?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 21:42:25
So simply, the DAO @Query("DELETE FROM Things WHERE someIdOfTheThing IN (:listOfId)") abstract fun deleteThings(listOfId: MutableList<String>): Maybe<Int> usage, mDisposables.add(mThingsDao .deleteThings(listOfId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ ... }, { ... }) ) and error, // Cannot access database on the main thread since it may potentially lock the UI for a long period of time. The simple idea i was thinking is to specify subscribeOn(Schedulers.io()) and then give all the job to Rx's magical hands, but failed. So what's the thing i'm

Cannot resolve symbol InstantTaskExecutorRule

纵饮孤独 提交于 2019-11-30 17:25:20
I open example code BasicRxJavaSample (from this article Room+RxJava ) The main thing is there: @Rule public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule(); And BasicRxJavaSample is all ok. But I can not apply this in my test. That's what's going on: Cannot resolve symbol InstantTaskExecutorRule And manual import does not work: My autocompletion works like this But should be so My app build.gradle ( full gradle here ): // tests testImplementation 'junit:junit:4.12' androidTestCompile "com.android.support:support-annotations:$supportVersion" testImplementation

Unable to create call adapter for io.reactivex.Observable

醉酒当歌 提交于 2019-11-30 11:42:42
问题 I'm going to send a simple get method to my server(it is Rails app) and get the result using RxJava and Retrofit. The thing that I did is: My interface: public interface ApiCall { String SERVICE_ENDPOINT = "https://198.50.214.15"; @GET("/api/post") io.reactivex.Observable<Post> getPost(); } My model is this: public class Post { @SerializedName("id") private String id; @SerializedName("body") private String body; @SerializedName("title") private String title; public String getId () { return id

Handle empty response with retrofit and rxjava 2.x

故事扮演 提交于 2019-11-30 11:07:47
When using rxjava 1.x i used to return Observable<Void> to handle empty response from retrofit: @POST( "login" ) Observable<Void> getToken( @Header( "Authorization" ) String authorization, @Header( "username" ) String username, @Header( "password" ) String password ); But since rxjava 2.x won't emit anything with Void is there any good practice to handle those empty responses? Completable was designed for such cases. It available since RxJava 1.1.1. From the official docs: Represents a deferred computation without any value but only indication for completion or exception. The class follows a