rx-android

Call same retrofit method sequentially for result using RxJava

半腔热情 提交于 2019-12-12 02:54:29
问题 Complete novice with RxJava here. So please bear with me. I have a Retrofit API which will upload a file. Looks like below @Multipart @POST("api") Observable<ImageUploadResponse> uploadImage(@Part("") MultipartBody.Part body); Also I have an ArrayList with Uri that I need to upload. When I went through the reactive tutorials, I saw that using "Observable.from" can help me in calling the API sequentially. Can some one please help me how to read the response from the API every time the API

Android rxjava with okhttp - NetworkOnMainThreadException

若如初见. 提交于 2019-12-12 02:32:42
问题 I sometimes get exception - android.os.NetworkOnMainThreadException, sometimes code works. Here is my code Observable.create(new Observable.OnSubscribe<Response>() { OkHttpClient client = new OkHttpClient(); @Override public void call(Subscriber<? super Response> subscriber) { try { Response response = client.newCall(request).execute(); subscriber.onNext(response); subscriber.onCompleted(); } catch (IOException e) { subscriber.onError(e); } } }).subscribeOn(Schedulers.io()) .observeOn

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

Calling four api's combining together using RxJava

只谈情不闲聊 提交于 2019-12-11 17:49:21
问题 I am new to RxJava Restapi.class /************/ @GET("app/dashboard") Observable<CategoryHomeModel[]> getCategories(@HeaderMap Map<String, String> headers); @GET("app/wallet/balance") Observable<WalletBalance> getWalletBalance(@HeaderMap Map<String, String> headers); @GET("/app/swap/myrateswaps") Observable<SwapSettings> rateMySwap(@HeaderMap Map<String, String> headers); @GET("/app/getsettings") Observable<Settings> getSettings(@HeaderMap Map<String, String> headers); /************/ I have

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.

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

How to add retryWhen() for limited time (Eg 3 time retries only) getting IOException

a 夏天 提交于 2019-12-11 16:07:16
问题 I am fetching response from server using 3 web API calls, but in case of getting IOException i have to retry those calls for 3 times using retryWhen(). How can I achieve that? i have tried adding below code, but not getting expected output retryWhen(new Function<io.reactivex.Observable<Throwable>, ObservableSource<?>>() { int retryCount = 0; @Override public ObservableSource<?> apply(io.reactivex.Observable<Throwable> errors) throws Exception { return errors.flatMap(new Function<Throwable,

Retrofit with RX runs OutOfMemory while trying to send a large BASE64

北城余情 提交于 2019-12-11 15:30:25
问题 I want to send a model throw Retrofit, which contains some standard fields and files, encoded in BASE64 format. I know, that this is a crazy way to send files, but I have a server with no backend developer. So, when I'm sending, for example, 3 pdf files 20mb each, I runs out of memory which exception like this Failed to allocate a 30544558 byte allocation with 2085152 free bytes and 26MB until OOM I figured out, that it's a problem in parse of base64 string, which I'm already have in memory

Why is OnComplete not called in this code? (RxAndroid)

帅比萌擦擦* 提交于 2019-12-11 13:54:32
问题 I know OnComplete of a Observer is called when all the items are emitted. In the below code, I am putting data from a cursor to an ArrayList in a flatMap operator. My cursor has 100 entries ( c.getCount() gives 100 ) and the size of my list is 100. The onNext is called 100 times too. But the onComplete is not called. I am populating a listview in onComplete. static int i = 0; final List<String> ar = new ArrayList<>(); ListView lv = ...; ArrayAdapter<String> adapter = ...; . . . q.subscribeOn

How do I pass a bodyparameter for Rx2AndroidNetworking for get requests?

强颜欢笑 提交于 2019-12-11 12:44:05
问题 I am working on retrieving some endpoints in a helper class with Rx2AndroidNetworking. However, there is no way I can pass "addBodyParameter" with get requests (only works for post and put requests". I was wondering if there's a way around it? My postman query looks like this (which does return proper results once i add the "my_session_token" in the body as shown below: However, I am not sure how that pans out with my code. My code for retrieving it is as follows: @Override public Single