rx-android

Rx Java mergeDelayError not working as expected

邮差的信 提交于 2019-11-29 03:12:10
I'm using RxJava in and Android application with RxAndroid. I'm using mergeDelayError to combine two retro fit network calls into one observable which will process emitted items if either emits one and the error if either has one. This is not working and it is only firing off the onError action when either encounters an error. Now to test this I shifted to a very simple example and still the successAction is never called when I have an onError call. See example below. Observable.mergeDelayError( Observable.error(new RuntimeException()), Observable.just("Hello") ) .observeOn(AndroidSchedulers

Periodic HTTP Requests Using RxJava and Retrofit

喜欢而已 提交于 2019-11-28 19:54:27
问题 Is it possible to use RxJava/RxAndroid and Retrofit to perform periodic http requests to update data every x seconds? Currently I am using an IntentService and Recursive Handler/Runnable that fires every x seconds. I'd like to know if I could remove all that and let RxJava handle the requests instead. final RestClient client = new RestClient(); final ApiService service = client.getApiService(); public interface ApiService { @GET("/athletes") public Observable<List<Athlete>> getAthletes(); }

How to stop and resume Observable.interval emiting ticks

安稳与你 提交于 2019-11-28 18:14:05
This will emit a tick every 5 seconds. Observable.interval(5, TimeUnit.SECONDS, Schedulers.io()) .subscribe(tick -> Log.d(TAG, "tick = "+tick)); To stop it you can use Schedulers.shutdown(); But then all the Schedulers stops and it is not possible to resume the ticking later. How can I stop and resume the emiting "gracefully"`? Here's one possible solution: class TickHandler { private AtomicLong lastTick = new AtomicLong(0L); private Subscription subscription; void resume() { System.out.println("resumed"); subscription = Observable.interval(5, TimeUnit.SECONDS, Schedulers.io()) .map(tick ->

Observable runs on main thread even though subscribeOn() is called on another thread

天涯浪子 提交于 2019-11-28 16:50:36
问题 I got a weird issue in one of my activities. When coming back from taking a picture / video, in my onActivityResult I am showing a dialog that lets the user name the camera. Once the user presses OK, I send onNext() to a subject with the requested file name that copies the file (and shows progress dialog). For some reason the map() function that does the copy is always called on the main thread, even though I call subscribeOn(Schedulers.io()) . @Override protected void onActivityResult(final

My subscriber's onNext and onComplete functions do not run when I call onNext within my FlowableOnSubscribe class

你。 提交于 2019-11-28 13:49:29
In an Android project that uses RxJava 2, I create a Flowable like this in the onCreate of my initial activity: Flowable.create(new MyFlowableOnSubscribe1(), BackpressureStrategy.BUFFER) .doOnComplete(new MyAction()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new MySubscriber()); The implementation of the FlowableOnSubscribe is: public class MyFlowableOnSubscribe1 implements FlowableOnSubscribe<String> { public static final String TAG = "XX MyFlOnSub1"; @Override public void subscribe(FlowableEmitter<String> emitter) { Log.i(TAG, "subscribe"); emitter

Rx Java Android : How to convert this callback block to Observer

冷暖自知 提交于 2019-11-28 13:47:32
问题 I'm trying to upload a file via Amazon's S3 Android SDK. I've used RX Java a bit but I'm not sure how to convert this method to a method that returns an Observable because I want to chain the result of this method to another Observable call. It confuses me I suppose because of the fact that this does not return right away and can't return until either OnError or OnState changes. How do I handle these situations in an RX way? public void uploadFile(TransferObserver transferObserver){

Retrofit2 Tail Recursion Using RxJava / RxAndroid

痞子三分冷 提交于 2019-11-28 11:29:56
问题 I am really trying to get a hang of using Retrofit with RxJava / RxAndroid . I've done this using normal Retrofit2 Callback method in a previous app without the use of Reactive Programming and it worked fine. So, here is it. I need to Tail Recall a function meant to fetch all Local Government from the server. The API uses pagination (I have to construct the URL with ?page=1, perPage=2) . I've to do this till I've the whole data. So, below is my Rx code public static Observable<LgaListResponse

multiple api request using retrofit and rx java

拟墨画扇 提交于 2019-11-28 09:29:06
I am new to android and I have a scenario where I want to get get data from multiple api. Let suppose api_a , api_b , api_c , api_d . These api are independent of each other but I want to show data from these api in a mix Recycler View ( horizontal and vertical ). So I want to make these api call in such a manner so that I can get every api data at a time so that i can display in recycler view. I already using retrofit 2 but for that I had to chain them one by one which is very lengthy and I think this is not a feasible approach. I know little bit about RX JAVA ,but I only know how to make one

How to ignore error and continue infinite stream?

↘锁芯ラ 提交于 2019-11-28 06:12:58
I would like to know how to ignore exceptions and continue infinite stream (in my case stream of locations)? I'm fetching current user position (using Android-ReactiveLocation ) and then sending them to my API (using Retrofit ). In my case, when exception occurs during network call (e.g. timeout) onError method is invoked and stream stops itself. How to avoid it? Activity: private RestService mRestService; private Subscription mSubscription; private LocationRequest mLocationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(100); ... private

RxTextView.textChanges with setText on Edittext

可紊 提交于 2019-11-28 04:37:31
问题 RxTextView.textChanges(editText) .map(CharSequence::toString) .debounce(200, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe(input -> { output = //...do something with input editText.setText(ouput) })); When I setText(output) it goes in loop. To set the text I first need to remove listener and then set listener again. How can I do this using RxJava ? 回答1: When I setText(output) it goes in loop. To set the text I first need to remove listener and then set listener