rx-android

Observable, retry on error and cache only if completed

♀尐吖头ヾ 提交于 2019-12-02 20:46:55
we can use the cache() operator to avoid executing a long task (http request) multiple times, and reuse its result: Observable apiCall = createApiCallObservable().cache(); // notice the .cache() --------------------------------------------- // the first time we need it apiCall.andSomeOtherStuff() .subscribe(subscriberA); --------------------------------------------- //in the future when we need it again apiCall.andSomeDifferentStuff() .subscribe(subscriberB); The first time, the http request is executed, but the second time, since we used the cache() operator, the request won't be executed but

Rxandroid What's the difference between SubscribeOn and ObserveOn

白昼怎懂夜的黑 提交于 2019-12-02 20:08:08
I am just learning Rx-java and Rxandroid2 and I am just confused what is the major difference between in SubscribeOn and ObserveOn. SubscribeOn specify the Scheduler on which an Observable will operate. ObserveOn specify the Scheduler on which an observer will observe this Observable. So basically SubscribeOn is mostly subscribed (executed) on a background thread ( you do not want to block the UI thread while waiting for the observable) and also in ObserveOn you want to observe the result on a main thread... If you are familiar with AsyncTask then SubscribeOn is similar to doInBackground

Unable to create call adapter for io.reactivex.Observable

夙愿已清 提交于 2019-12-02 19:52:59
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; } public String getBody () { return body; } public String getTitle () { return title; } } And this is

How to perform multiple API call synchronously or call API sequentially using RxAndroid or RxJava

与世无争的帅哥 提交于 2019-12-02 19:21:11
问题 Hi There I am new in RxJava I am trying to call two API sequential the result of one api used as input to other and lastly return value of second app Currently I am trying with below code public Single<List<LocationParcelableItem>> getUpdateRecentLocation( LocationViewType locationViewType, Map<String, String[]> filter) { return locationRepository .getRecentLocations(filter) .subscribeOn(Schedulers.io()) .flatMapMaybe(this::updateRecentLocationList) .flatMapSingle(userLocationParcelableItem -

How do I get Response body when there is an error when using Retrofit 2.0 Observables

冷暖自知 提交于 2019-12-02 17:59:51
I am using Retrofit 2.0 to make api calls that return Observables. It all works good when the call went through fine and the response is as expected. Now let's say we have an error response, it throws an onError. I would like to read the response body even when it is an Error. Example @FormUrlEncoded @POST("tokenLogin") Observable<LoginResponse> loginWithToken( @Field("token") String pin ); When the request and response are valid, I get the right observable and onError is being called as expected when there is an error. Correct Response: { "status" : "authenticated" } The Observable converts

How to transform a nested list of double values into a Java class using RxJava?

Deadly 提交于 2019-12-02 04:18:24
In my Android client I receive this JSON data from a backend: [ [ 1427378400000, 553 ], [ 1427382000000, 553 ] ] Here is the routine which actually loads the data. I am using RxAndroid and Retrofit here. private void getProductLevels() { Observable<List<List<Double>>> responseObservable = mProductService.readProductLevels(); AppObservable.bindFragment(this, responseObservable) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) // TODO: Transform List<List<Double>> into List<ProductLevel> .subscribe(new Subscriber<List<List<Double>>>() { @Override public void onCompleted()

Difference between RxJava and RxAndroid?

走远了吗. 提交于 2019-12-01 15:01:00
Why do we need to use RxAndroid with RxJava? What is the functional difference between them and actual use of RxAndroid and RxJava? I can't find proper answer for this. RxAndroid can be understood as an extension to RxJava , that helps you to use it on Android platform easily. See the description on RxAndroid Github repository : Android specific bindings for RxJava 2. This module adds the minimum classes to RxJava that make writing reactive components in Android applications easy and hassle-free. More specifically, it provides a Scheduler that schedules on the main thread or any given Looper.

Difference between RxJava and RxAndroid?

爱⌒轻易说出口 提交于 2019-12-01 13:47:38
问题 Why do we need to use RxAndroid with RxJava? What is the functional difference between them and actual use of RxAndroid and RxJava? I can't find proper answer for this. 回答1: RxAndroid can be understood as an extension to RxJava , that helps you to use it on Android platform easily. See the description on RxAndroid Github repository: Android specific bindings for RxJava 2. This module adds the minimum classes to RxJava that make writing reactive components in Android applications easy and

How to cancel request with retofit2 and RxAndroid

ぃ、小莉子 提交于 2019-12-01 04:12:34
I am using Retrofit 2.0 and Rx-android to load my APIs. I follow the section RxJava Integration with CallAdapter at this site and it work fine. But, I don't know how to cancel a loading request with the observable object. Please help to give me an idea. The only way to cancel RxJava Observable execution - unsubscribe from it. RxJavaCallAdapter will delegate cancel to okhttp client. So, you simple do smth like this: Subscription subscription = getObservable().subscribe(); //When you want to stop execution subscription.unsubsribe(); You can check out the code here . Concretely these lines if

How to cancel request with retofit2 and RxAndroid

自作多情 提交于 2019-12-01 01:58:56
问题 I am using Retrofit 2.0 and Rx-android to load my APIs. I follow the section RxJava Integration with CallAdapter at this site and it work fine. But, I don't know how to cancel a loading request with the observable object. Please help to give me an idea. 回答1: The only way to cancel RxJava Observable execution - unsubscribe from it. RxJavaCallAdapter will delegate cancel to okhttp client. So, you simple do smth like this: Subscription subscription = getObservable().subscribe(); //When you want