rx-java2

How to retry Retrofit call on HTTP errors (401) when using RxJava?

旧巷老猫 提交于 2019-12-12 13:00:54
问题 My current Android Application is employing Retrofit(2.4.0) and RxJava(2.1.16) to execute my Web Service calls. Im using Google SignIn for my User Authentication. I want my Retrofit calls to detect HTTP 401 (UNAUTHORIZED) and attempt to Silently Login with Google Signin then retry the Retrofit call. My retrofit calls resemble this @Headers(HEADER_ACCEPT_JSON) @GET("resources") Observable<Response<String>> getResources(@Header(HEADER_AUTHORIZATION) @NonNull final String authenticationToken,

Cannot resolve symbol InstantTaskExecutorRule

安稳与你 提交于 2019-12-12 07:16:58
问题 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

Q : RxJava : How the clear (CompositeDisposable) method work internally

喜欢而已 提交于 2019-12-12 03:59:15
问题 Anonymous class hold a reference to the enclosing class. In the following example, I created a small Activity. In the onCreate method, I just add a timer on another Thread, add a CompositeDisposable and clear it in the onDestroy. Obviously without the CompositeDisposable, it will create a memory leak. With the CompositeDisposable it doesn't create any memory leak but how is it even working ? RxJava just interrupt the Thread and put null on every callback ? Can you provide some line that do

rxjava 2.0 what is the difference between Observable.subscribe and Observable.subscribeActual?

試著忘記壹切 提交于 2019-12-11 17:56:35
问题 The documentation just says protected abstract void subscribeActual(Observer<? super T> observer) Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic. There is no need to call any of the plugin hooks on the current Observable instance or the Subscriber . 回答1: Observable.subscribe comes from the base interface definition in ObservableSource and is the main subscription method for Observable s: internal and external

RxJava 2: flatMapCompletable is not waiting for the Completable to finish

穿精又带淫゛_ 提交于 2019-12-11 17:51:55
问题 The use case: There is a dataset of a POJO class. In this case it is an ArrayList . I have created a class which extends ArrayList with some helper methods which divides the list into pages. A page just divides the list into small pages for uploading to a REST API. I have created an Iterable from an Iterator , which checks whether a page is available for uploading and then fetches that page. The page needs to uploaded and on a success event of the upload, it will be removed and then again the

RxAndroidBle: Setup notification, write on characteristic and wait for notification to proceed

狂风中的少年 提交于 2019-12-11 17:09:41
问题 I am using Polidea's RxAndroidBle library to communicate with a Device in my Android application. I am very new to Reactive Programming so I can't figure out exactly how to do the following: Setup Notification in one characteristic (Characteristic A). When notification setup is done, write to another characteristic (Characteristic B). This will trigger a Notification coming from Characteristic A. When the write operation is done, wait for the arrival of the Notification in Characteristic A.

Group data with RXJava 2, add element to each group and output one list

我是研究僧i 提交于 2019-12-11 16:54:12
问题 I have an RXJava 2 observer that emits objects of type somethingWithDate . These objects have a property that contains a java date object as well as a boolean isHeader . What I need to do with these objects is: Group them by month and year (all dates in January of 2017, all dates in January of 2016, all dates in February 2016, ...) Add a header (also a somethingWithDate ) at the start of the group Sort groups in regard to each other (by date, sorting inside the groups would be nice too but

Observer class must be declared abstract or implement an abstract method

若如初见. 提交于 2019-12-11 16:49:40
问题 I want to use RxAndroid and RxJava in my project. But as shown in the below code, in getAnimalsObserver() method, the following line: return new Observer<String> is underscored with a red line saying: //class must be either declared abstract or implement abstract method please let me know how to fix that error. code : import rx.Observable; import rx.Observer; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; //class must be either declared abstract or implement

HTTP FAILED: java.net.SocketException: Socket closed Retrofit

南楼画角 提交于 2019-12-11 15:56:34
问题 tried with multiple ways still facing this issue as I am using RxJava and Retrofit to do all my network operations. Below is my code. <-- HTTP FAILED: java.net.SocketException: Socket closed Service.kt @GET("/v1/contact/{id}") fun getContactDetails(@Path("id") id:String): Flowable<ContactDetailResponse> AccountRepositoryImpl.kt override fun contactDetails(contactId:String) { mContactResponse.loading(true) remote.getContactDetails(contactId) .performOnBackOutOnMain(scheduler) .subscribe({ data

Retrofit Observable response to LiveData object using subscribe

微笑、不失礼 提交于 2019-12-11 15:13:00
问题 I have inherited this project that was using retrofit incorrectly with LiveData by trying to convert responses to LiveData immediately. I am in the middle of trying to refactor, but am getting stuck with converting an RxJava Observable to a LiveData object in the ViewModel. Here is what I have so far: Retrofit Service interface Service { @POST("user/login") fun postLogin(@Body body: LoginBody) Observable<ApiResponseWrapper<LoginRemote>> } As you can see, Observable wraps an ApiResponseWrapper