rx-java

RXJava how to try to get next after x time

纵饮孤独 提交于 2019-12-23 10:02:29
问题 I wan to do a call to a web service using retrofit every x seconds until y condition is raised. I want to run OrderApi.get after x seconds until the response is null. public class OrderApi {} public static Observable<Order> get() { //... } } OrderApi.get(order.getId())) .subscribe(updatedOrder -> { mShouldRun = updatedOrder != null; }); Already saw operators like Observable.delay Observable.timber but I cant find a way to use them properly. 回答1: this should work Observable.interval(1,

Why debounce() with toList() doen't working in RxAndroid?

此生再无相见时 提交于 2019-12-23 09:25:32
问题 While I'm using debounce() ,then fetch data from backend and the data I want to convert to another data and lastly use toList() . when I'm using toList() nothing happens no any log not in subscribe and error ,without toList() it works and subscribe() method enters as much as I have list of books, I tested the second part of code it without debounce() just getItems() and using toList() it works. Below is my code the first part with debounce() and itList() which is not working and the second

Implement retryWhen logic

家住魔仙堡 提交于 2019-12-23 09:14:52
问题 I have an app which requires session (cookies) to process web calls. Im using Retrofit+RxJava . However, session could expire (Retrofit error with 401 Unauthorized status) and i want to reauthenticate (to get fresh cookies) and retry previous call in this case. How would i do it with RxJava ? My example: getServerApi().getDialogs(offset, getCookies()) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .retryWhen(observable -> {...}) // Need some logic .subscribe

Collect grouped observables' emissions into one list

谁说我不能喝 提交于 2019-12-23 07:35:08
问题 I have the following use case (this is of course a contrived example, but once I know the answer, I will be able to port it to a real problem I am to solve): Get a list of integers. Group them by the result of the % 4 operation Collect the each group's elements to lists Ignore any groups/lists which have fewer elements than 3 elements Emit a single list, whose elements are the lists created in step #3 Here is my current code: Observable .from(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11,

Collect grouped observables' emissions into one list

柔情痞子 提交于 2019-12-23 07:34:58
问题 I have the following use case (this is of course a contrived example, but once I know the answer, I will be able to port it to a real problem I am to solve): Get a list of integers. Group them by the result of the % 4 operation Collect the each group's elements to lists Ignore any groups/lists which have fewer elements than 3 elements Emit a single list, whose elements are the lists created in step #3 Here is my current code: Observable .from(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11,

Where to quit the handler thread that used for realm operations in Android?

試著忘記壹切 提交于 2019-12-23 05:34:19
问题 I have an android application that I do many realm operations . I wanted to do those stuff on background and to do that I have used handler threads . I also used handler threads in some of my activities and service classes and I quit() those handler threads inside of onTerminate() or onDestroy() methods. However I do not know where should I quit the handler thread when I use it inside if a non-activity classes since they do not have onDestroy() methods. I have commented the handlerThread.quit

request in another request called several times with rxJava and retrofit

a 夏天 提交于 2019-12-23 05:15:28
问题 I'm using MVVM and rxJava and retrofit to send my request. I have a bottom navigation view which has 5 fragments and in one of them, I have to send a request and after it, the response is delivered, I have to send another request to my server. this is my ViewModel class : class MyViewModel: ViewModel() { val compositeDisposable = CompositeDisposable() val myFirstReqLiveData = MutableLiveData<myFirstReqModel>() val mySecondReqLiveData = MutableLiveData<mySecondReqModel>() fun getFirstReq(token

How to batch long process in serial using RxJava?

我是研究僧i 提交于 2019-12-22 18:48:12
问题 I have a big list of strings that needs to be checked against remote API. Observable.from(List<String> strings) // let's say the `strings` has > 5000 items .buffer(50) // splitting the strings into 50-sized chunks, it returns Observable<List<String>> (fast) .flatMap((strings) -> { // checkPhoneNumbers is a network call using Retrofit's RxJava (slow) return mSyncApi.checkPhoneNumbers(strings); }) .reduce( ... ) // aggregate all checking results .subscribe( ... ); The problem is buffer() seems

RxJava2 get event when Observable/Completed is completed or disposed

扶醉桌前 提交于 2019-12-22 18:31:05
问题 I need to show a progress dialog when I subscribe to a Completable and hide it after the operation is completed(successfully or with an error) or is canceled. So I do final Completable completable = notificationRepository.markAllAsRead() .doOnSubscribe(d -> progressDialog.show()) .doOnError(error -> progressDialog.dismiss()) .doOnComplete(() -> progressDialog.dismiss()) .doOnDispose(() -> progressDialog.dismiss()); Is there any elegant way to get single callback when onError , onComplete or

Handling long running tasks with RxJava

℡╲_俬逩灬. 提交于 2019-12-22 17:58:46
问题 I'm trying to migrate an AsyncTask that sends messages to the server, to use RxJava. Roughly, the task does the following: 1) Creates a message that will be sent (persists to the database) 2) Shows the message to the user (state 'sending') 3) Sends the message to the server (code snippet below) 4) Marks the message as sent or failed (persists to the database) 5) Updates the UI I've created the required Rx chain which partially looks like this: public Observable<Message> sendMessage(Message