Questions tagged [rx-java]

RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.

Filter by
Sorted by
Tagged with
261
votes
9answers
89k views

When should one use RxJava Observable and when simple Callback on Android?

I'm working on networking for my app. So I decided to try out Square's Retrofit. I see that they support simple Callback @GET("/user/{id}/photo") void getUserPhoto(@Path("id") int ...
253
votes
3answers
25k views

Use cases for RxJava schedulers

In RxJava there are 5 different schedulers to choose from: immediate(): Creates and returns a Scheduler that executes work immediately on the current thread. trampoline(): Creates and returns ...
194
votes
2answers
62k views

Difference between CompletableFuture, Future and RxJava's Observable

I would like to know the difference between CompletableFuture,Future and Observable RxJava. What I know is all are asynchronous but Future.get() blocks the thread CompletableFuture gives the ...
180
votes
10answers
106k views

When do you use map vs flatMap in RxJava?

When do you use map vs flatMap in RxJava? Say, for example, we want to map Files containing JSON into Strings that contain the JSON-- Using map, we have to deal with the Exception somehow. But how?: ...
149
votes
7answers
57k views

What is the difference between flatmap and switchmap in RxJava?

The rxjava doc definition of switchmap is rather vague and it links to the same page as flatmap. What is the difference between the two operators?
144
votes
7answers
43k views

Difference between Java 8 streams and RxJava observables

Are Java 8 streams similar to RxJava observables? Java 8 stream definition: Classes in the new java.util.stream package provide a Stream API to support functional-style operations on streams of ...
126
votes
3answers
41k views

Observable vs Flowable rxJava2

I have been looking at new rx java 2 and I'm not quite sure I understand the idea of backpressure anymore... I'm aware that we have Observable that does not have backpressure support and Flowable ...
112
votes
2answers
24k views

What is the difference between Observable, Completable and Single in RxJava

Can anyone please explain the difference between Observable, Completable and Single in RxJava with clear examples? In which scenario we use one over the others?
106
votes
3answers
54k views

Get response status code using Retrofit 2.0 and RxJava

I'm trying to upgrade to Retrofit 2.0 and add RxJava in my android project. I'm making an api call and want to retrieve the error code in case of an error response from the server. Observable<...
93
votes
3answers
39k views

Unable to create call adapter for io.reactivex.Observable

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 ...
90
votes
14answers
44k views

rxjava: Can I use retry() but with delay?

I am using rxjava in my Android app to handle network requests asynchronously. Now I would like to retry a failed network request only after a certain time has passed. Is there any way to use retry() ...
84
votes
8answers
71k views

Combine a list of Observables and wait until all completed

TL;DR How to convert Task.whenAll(List<Task>) into RxJava? My existing code uses Bolts to build up a list of asynchronous tasks and waits until all of those tasks finish before performing other ...
84
votes
1answer
15k views

Retrofit with Rxjava Schedulers.newThread() vs Schedulers.io()

What are the benefits to use Schedulers.newThread() vs Schedulers.io() in Retrofit network request. I have seen many examples that use io(), but I want to understand why. Example situation: ...
82
votes
4answers
32k views

What is the difference between an Observer and a Subscriber?

I am trying to decipher the following function: Subscription getCar(id, Observer<Car> observer) { return getCarDetails(id, new Observer<CarDetails> { @...
76
votes
8answers
20k views

In RxJava, how to pass a variable along when chaining observables?

I am chaining async operations using RxJava, and I'd like to pass some variable downstream: Observable .from(modifications) .flatmap( (data1) -> { return op1(data1); }) ... .flatmap( (...
75
votes
3answers
53k views

How to use CompositeDisposable of RxJava 2?

In RxJava 1, there was CompositeSubscription, but that is not present in RxJava2, There is something CompositeDisposable in rxJava2. How do I use CompositeDisposable or Disposable in RxJava2?
65
votes
4answers
14k views

Difference between RxJava API and the Java 9 Flow API

It seems on every iteration of Java for the last few major releases, there are consistently new ways to manage concurrent tasks. In Java 9, we have the Flow API which resembles the Flowable API of ...
64
votes
15answers
43k views

RxJava delay for each item of list emitted

I'm struggling to implement something I assumed would be fairly simple in Rx. I have a list of items, and I want to have each item emitted with a delay. It seems the Rx delay() operator just shifts ...
64
votes
2answers
19k views

Kotlin: Whats does “return@” mean?

I'm using RxJava in one of my projects, I converted one of my classes to Kotlin using the Android Studio plugin and in one of map flatMap lambda (Func1 in java), intermediates returns looks like the ...
59
votes
9answers
57k views

RxJava: How to convert List of objects to List of another objects

I have the List of SourceObjects and I need to convert it to the List of ResultObjects. I can fetch one object to another using method of ResultObject: convertFromSource(srcObj); of course I can do ...
59
votes
2answers
39k views

What is the purpose of doOnNext(…) in RxJava

When should we use doOnNext() from Observable instead of just onNext()?
58
votes
4answers
29k views

How to chain two Completable in RxJava2

I have two Completable. I would like to do following scenario: If first Completable gets to onComplete , continue with second Completable. The final results would be onComplete of second Completable. ...
58
votes
2answers
36k views

Convert Observable<List<Car>> to a sequence of Observable<Car> in RxJava

Given a list of cars (List<Car> cars), I can do: Observable.just(cars); //returns an Observable that emits one List<Car> Observable.from(cars); //returns an Observable that emits a ...
56
votes
5answers
21k views

@DELETE method is not supporting(Non-body HTTP method cannot contain @Body or @TypedOutput.)

@DELETE("/job/deletejob") Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model); am getting this error: Non-body HTTP method cannot contain @Body or @TypedOutput ...
56
votes
10answers
25k views

Android RxJava 2 JUnit test - getMainLooper in android.os.Looper not mocked RuntimeException

I am encountering a RuntimeException when attempting to run JUnit tests for a presenter that is using observeOn(AndroidSchedulers.mainThread()). Since they are pure JUnit tests and not Android ...
55
votes
2answers
33k views

RxJava Fetching Observables In Parallel

I need some help in implementing parallel asynchronous calls in RxJava. I have picked up a simple use case wherein the FIRST call fetches (rather searches) a list of products (Tile) to be displayed. ...
54
votes
7answers
66k views

Rxjava Android how to use the Zip operator

I am having a lot of trouble understanding the zip operator in RxJava for my android project. Problem I need to be able to send a network request to upload a video Then i need to send a network ...
53
votes
4answers
16k views

What is the difference between EventBus and RxJava? [duplicate]

I am confused about the difference between EventBus and RxJava in android. I need to implement one of them for my issue about notifying some components when some changes have been done, so that they ...
50
votes
4answers
11k views

Rxandroid What's the difference between SubscribeOn and ObserveOn

I am just learning Rx-java and Rxandroid2 and I am just confused what is the major difference between in SubscribeOn and ObserveOn.
48
votes
2answers
31k views

Concat VS Merge operator

I was checking the documentation of RXJava and I notice that concat and merge operators seems do the same. I wrote a couple test to be sure. @Test public void testContact() { Observable.concat(...
48
votes
1answer
14k views

Subscribewith Vs subscribe in RxJava2(Android)?

When to call the subscribeWith method rather than plain subscribe? And what is the use case? compositeDisposable.add(get() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers....
47
votes
9answers
40k views

How to ignore error and continue infinite stream?

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 ...
47
votes
1answer
12k views

RxJava: difference between doOnNext and doOnEach

In which cases I should use doOnNext, and in which cases doOnEach? .doOnEach(new Action1<Notification<? super MessageProfile>>() { @Override public void ...
46
votes
5answers
20k views

What is the difference between concatMap and flatMap in RxJava

It seems that these 2 functions are pretty similar. They have same signature (accepting rx.functions.Func1<? super T, ? extends Observable<? extends R>> func), and their marble diagrams ...
46
votes
1answer
15k views

If the onComplete call is made for a RxJava Subject, do i have to manually unsubscribe again?

I'm using an RxJava ReplaySubject in my Fragment. I'm attempting to use the ReplaySubject in a way, where I would like the Subject to execute a process until completion (possibly beyond the life of ...
45
votes
2answers
2k views

Why is RxJava often used with Retrofit?

What is the benefit of using Retrofit in combination with Rxjava?
44
votes
2answers
20k views

rxjava merge observables of different type

I'm new to rxjava. I need to combine two observables that emit objects of different type. Something like Observable<Milk> and Observable<Cereals> and get a Observable<CerealsWithMilk>...
44
votes
4answers
48k views

RxJava - fetch every item on the list

I have a method that returns an Observable<ArrayList<Long>>, which are ids of some Items. I'd like to go through this list and download every Item using another method that returns ...
43
votes
3answers
33k views

RxJava: chaining observables

Is it possible to implement something like next chaining using RxJava: loginObservable() .then( (someData) -> { // returns another Observable<T> with some long operation ...
41
votes
2answers
31k views

RxJava Observing on calling/subscribing thread

I have some trouble understandig how subscribeOn/observeOn works in RxJava. I've created simple app with observable that emits solar system planet names, does some mapping and filtering and prints ...
41
votes
1answer
14k views

How to create a retrofit.Response object during Unit Testing with Retrofit 2

While using RxJava and Retrofit 2 I am trying to create Unit Tests to cover when my app receives specific responses. The issue I have is that with Retrofit 2 I cannot see a nice way of creating a ...
39
votes
6answers
41k views

Observable which does not pass anything in onNext()

I would need an Observable, for example to provide a system clock, which does not need to pass anything in onNext(). I couldn't find a signature that would allow me to do that. Sure, I could use any ...
39
votes
4answers
16k views

What is CompositeDisposable in RxJava

I am an Android Student. I want to learn RxJava. My Question is "What is CompositeDisposable in RxJava?". Please describe in detail.
38
votes
8answers
35k views

Convert observable to list

I am using RxJava. I have an Observable<T>. How do I convert it to List<T>? Seems to be a simple operation, but I couldn't find it anywhere on the net.
38
votes
10answers
13k views

Deliver the first item immediately, 'debounce' following items

Consider the following use case: need to deliver first item as soon as possible need to debounce following events with 1 second timeout I ended up implementing custom operator based on ...
38
votes
4answers
23k views

RxJava: Error occurred when trying to propagate error to Observer.onError

I am getting a IllegalStateException error in the Rx Library and don't know exactly where the root of the issue is, whether it is with RxJava or something I may be doing incorrectly. The fatal crash ...
38
votes
4answers
13k views

EventBus/PubSub vs (reactive extensions) RX with respect to code clarity in a single threaded application

Currently, I am using an EventBus/PubSub architecture/pattern with Scala (and JavaFX) to implement a simple note organizing app (sort of like an Evernote client with some added mind mapping ...
37
votes
5answers
30k views

How to create an Observable from OnClick Event Android?

I'm new in reactive programming. So I have problem when create a stream from an Event, like onClick, ontouch... Can anyone help me solve this problem. Thanks.
37
votes
3answers
38k views

How can PublishSubject and BehaviorSubject be unsubscribed from?

Under the subjects package you have classes like PublishSubject and BehaviorSubject which I suppose can be described as some usable sample Observables. How can these subjects be unsubscribed from? ...
36
votes
7answers
37k views

How to call a method after a delay in android using rxjava?

I'm trying to replace my Handler method with RxJava. My requirement: I want to call the method getTransactionDetails() only after 5 seconds. This my working code using Handler: new Handler()....

1
2 3 4 5
127