Questions tagged [rx-java2]

anything related to RxJava2 – The new implementation of the 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
186
votes
9answers
45k views

When to use RxJava in Android and when to use LiveData from Android Architectural Components?

I am not getting the reason to use RxJava in Android and LiveData from Android Architectural Components.It would be really helpful if the usecases and differences between the both are explained along ...
133
votes
8answers
38k views

The result of subscribe is not used

I've upgraded to Android Studio 3.1 today, which seems to have added a few more lint checks. One of these lint checks is for one-shot RxJava2 subscribe() calls that are not stored in a variable. For ...
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?
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 ...
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 ...
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. ...
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 ...
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
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....
42
votes
3answers
16k views

When to call dispose and clear on CompositeDisposable

My question can be a duplicate of How to use CompositeDisposable of RxJava 2? But asking to clear one more doubt. According to the accepted answer // Using clear will clear all, but can accept new ...
39
votes
4answers
26k views

RxJava2 observable take throws UndeliverableException

As I understand RxJava2 values.take(1) creates another Observable that contains only one element from the original Observable. Which MUST NOT throw an exception as it is filtered out by the effect of ...
37
votes
6answers
14k views

Cannot resolve symbol InstantTaskExecutorRule

I open example code BasicRxJavaSample (from this article Room+RxJava) The main thing is there: @Rule public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule(); And ...
36
votes
6answers
12k views

RxJava 2.x: Should I use Flowable or Single/Completable?

I'm developing an Android app using Clean Architecture and I'm migrating it to RxJava 2.x. I have to make some network requests to a soap service, so I defined the api interface in the domain module: ...
29
votes
5answers
12k views

How to convert rxJava2's Observable to Completable?

I have Observable stream, and I want to convert it to Completable, how I could do that?
29
votes
6answers
18k views

RxJava flatMapIterable with a Single

I'm trying to tidy up my code a little, and Single is looking like a good choice for me as I'm doing something that will only ever emit one result. I'm having an issue though as I was using ...
28
votes
3answers
5k views

RxJavaPlugins Error Didn't find class “com.google.devtools.build.android.desugar.runtime.ThrowableExtension”

After upgrading Android Studio 3.0 Beta 1 getting the following error. When I downgraded the error disappeared. Studio Build: Android Studio 3.0 Beta 1 Version of Gradle Plugin: 'com.android....
28
votes
2answers
8k views

Do I have to unsubscribe from completed observable?

If an observable completes, do I still have to unsubscribe / dispose (in RxJava2) the observable to remove the Observer (prevent memory leaks) or is this handled internally by RxJava once a onComplete ...
25
votes
4answers
13k views

RxJava Single.just() vs Single.fromCallable()?

I wondered if someone can shed some light on this question, when to use Single.fromCallable( ()-> myObject ) instead of Single.just(myObject) from the documentation, Single.fromCallable(): /...
25
votes
1answer
8k views

Difference between doAfterTerminate and doFinally

Does anybody knows what is the difference between operators "doAfterTerminate" and "doFinally" in RxJava 2 ?
25
votes
2answers
14k views

Is there something like Single.empty()

I'm in the process of migrating from Rx 1 to Rx 2 and suddenly while reading through posts I found out that Single should be the type of observable to use for retrofit calls. So I've decided to give ...
24
votes
2answers
11k views

Observable.combineLatest type inference in kotlin

I'm using RxJava2, Kotlin-1.1 along with RxBindings in my project. I have simple login screen with 'login' button disabled by default, I want to enable the button only when username and password ...
24
votes
6answers
18k views

Reactive Programming Advantages/Disadvantages

I keep studying and trying Reactive Style of coding using Reactor and RxJava. I do understand that reactive coding makes better utilization of CPU compared to single threaded execution. Is there any ...
22
votes
4answers
13k views

Cannot resolve symbol AndroidSchedulers

I'm using version 2.0.0 of RxJava, and it seems like I have no access to AndroidSchedulers. I'm unable to get access to mainthread through RxJava
22
votes
4answers
8k views

Handle empty response with retrofit and rxjava 2.x

When using rxjava 1.x i used to return Observable<Void> to handle empty response from retrofit: @POST( "login" ) Observable<Void> getToken( @Header( "Authorization" ) String authorization,...
22
votes
2answers
7k views

What is the difference between RxJava 2 Cancellable and Disposable?

I want to create an Observable from view click listener using RxJava 2. I started from the simplest implementation (I don't use lambdas here to show you different types in this method): Observable&...
22
votes
6answers
25k views

How to reset a BehaviorSubject

I have a BehaviorSubject that I would like to reset - by that I mean I want the latest value to not be available, just as if it was just created. I don't seem to see an API to do this but I suppose ...
22
votes
3answers
12k views

Best practice for disposing Completable, Single, Maybe and terminating Observables in RxJava

I'm asking this from an Android perspective, but this should apply to RxJava in general. As a best practice, should my view always dispose of even short lived Completable, Single, Maybe and ...
21
votes
2answers
3k views

Can't subscribe on a RxJava 2 Observable with TestSubscriber

Why is my compiler not allowing myself to subscribe on an Observable with a TestSubscriber? Here's my code: TestSubscriber<User> testSubscriber = new TestSubscriber<>(); Observable.just(...
20
votes
3answers
9k views

Convert RxJava Observables To Live Data With Kotlin Extension Functions

I've been using alot of RxJava Observables converted to LiveData in my code using LiveDataReactiveStreams.fromPublisher() library. So I though of adding an extension function to the RxJava Observable ...
20
votes
2answers
7k views

How to convert a List<Object> to PagedList<Object> and vice-versa?

PagedList<Object> is used for Android's cool paging library. To make the question as minimal as possible : If i have a list of strings like List<String> stringList; // it consists of ...
19
votes
1answer
6k views

Run void method in background

I want to run a method in background using rxjava. I don't care about the result. void myHeavyMethod() { (...) } So far the only solution I have is to modify the return type to e.g. boolean. ...
19
votes
4answers
1k views

What's the difference between curly braces and normal brackets in RxJava with Kotlin

I don't understand the real difference between the curly braces and and the normal brackets in Kotlin when using RxJava. For example, I have the following code which works as expected: ...
18
votes
2answers
9k views

RxJava `Completable.andThen` is not executing serially?

I have a usecase where I initiallize some global variables in a Completable , and in the next step in the chain (using andThen operator) I make use of those variables. Following sample explains my ...
18
votes
4answers
4k views

Synchronous or Asynchronous Rxjava inside the Worker (from WorkManager component) what's the right choice?

I'm new to the new architecture component WorkManager, I do my API calls via Retrofit and RxJava. My use case here is to get new posts from the Backend, then show notification, and update a widget. ...
17
votes
4answers
12k views

How to handel no results with Android Room and RxJava 2?

I have database with table contact and I want to check if there is contact with some phone number. @Query("SELECT * FROM contact WHERE phone_number = :number") Flowable<Contact> ...
17
votes
5answers
15k views

How to pass null to an Observable with nullable type in RxJava 2 and Kotlin

I initialize my variable like this:- val user: BehaviorSubject<User?> user = BehaviorSubject.create() But I can't do this. IDE throws an error:- user.onNext(null) And doing this, IDE says u ...
17
votes
4answers
5k views

Android Dagger2 + OkHttp + Retrofit dependency cycle error

Hey there I am using Dagger2, Retrofit and OkHttp and I am facing dependency cycle issue. When providing OkHttp : @Provides @ApplicationScope OkHttpClient provideOkHttpClient(TokenAuthenticator ...
17
votes
2answers
17k views

How to use “if-else” in RX java chain?

I am a newer on RXJava/RXAndroid. I want to implement this case: chose different way based on some condition in RXJava. For example, first, I fetch user info from network and if this is a VIP user, I ...
17
votes
2answers
14k views

Retrofit 2 + RxJava cancel/unsubscribe

I am performing a network request where I send files and a message. I would like to have an option to cancel current request. I have found two similar questions and both suggests that observable....
17
votes
2answers
5k views

RxJava Relay vs Subjects

I'm trying to understand the purpose of this library by Jake Warthon: https://github.com/JakeWharton/RxRelay Basically: A Subject except without the ability to call onComplete or onError. ...
16
votes
2answers
6k views

RxJava zipWith IDE error in Kotlin using Android Studio 3.0

I want to create an Observable which emits some items from and Observable containing list of objects with Interval Observable, so that the items from the first observable will be emitting with some ...
16
votes
1answer
11k views

RxJava 2.0 - How to convert Observable to Publisher

How to convert Observable to Publisher in RxJava version 2? In the first version we have the https://github.com/ReactiveX/RxJavaReactiveStreams project that do exactly what I need. But How can I do ...
16
votes
2answers
7k views

Chain Completable into Observable flow

Suppose you want to insert a Completable in your Observable chain, such as for each emitted element, there is a completable that runs and blocks until it completes, what option would you choose? (here ...
16
votes
2answers
8k views

RxJava Scheduler to observe on main thread

If I write something like this, then both the operation and notification will be on the current thread... Observable.fromCallable(() -> "Do Something") .subscribe(System.out::println); If I ...
14
votes
3answers
12k views

Filter list of objects in RxJava

I am trying to filter the list on the basis of it's property. For example, Sensors class has a property isActive and I want to get all the objects with isActive as true but I am unable to do it. I ...
14
votes
4answers
7k views

Cannot resolve method Observable.from in rxjava 2

There is a from method in the Observable class in rxjava 1 but not found in rxjava 2. How can I replace the from method in rxjava 2 in the following code: List<Integer> ints = new ArrayList&...
14
votes
2answers
7k views

Is it recommended to call Disposable.dispose() as soon as a subscription completes work?

I have an Activity in which I'm creating and subscribing to multiple instances of the Single class (each doing some work in a separate background thread). For each subscription, I'm adding the ...
14
votes
2answers
4k views

When to dispose RxJava2 Disposable in ViewModel?

I'm using ViewModel from Android Architecture Components in my app. In the ViewModel, I'm using RxJava2 subscription and I keep Disposable object after I subscribe. Before, when I did this in Activity,...
14
votes
1answer
14k views

The mapper function returned a null value [duplicate]

I set same build types for debug and release, buildTypes { debug { buildConfigField "String", "API_BASE_URL", "\"https://www.testUrl.com/api/\"" minifyEnabled true ...

1
2 3 4 5
77