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
229 votes
10 answers
65k 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 ...
user avatar
  • 2,413
152 votes
8 answers
57k 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 ...
user avatar
  • 9,747
136 votes
3 answers
37k 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?
user avatar
  • 6,759
107 votes
3 answers
53k 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 ...
user avatar
96 votes
6 answers
30k 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.
user avatar
  • 1,809
80 votes
3 answers
62k 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?
user avatar
79 votes
5 answers
42k 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. ...
user avatar
78 votes
7 answers
32k 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 ...
user avatar
  • 2,636
73 votes
4 answers
16k 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 ...
user avatar
  • 7,552
71 votes
10 answers
37k 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 ...
user avatar
  • 11.2k
62 votes
3 answers
31k 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 ...
user avatar
52 votes
1 answer
18k 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....
user avatar
  • 5,505
42 votes
6 answers
31k 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 ...
user avatar
  • 1,579
41 votes
4 answers
35k 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 ...
user avatar
  • 1,263
41 votes
6 answers
15k 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: ...
user avatar
37 votes
4 answers
27k 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(): /...
user avatar
  • 5,505
35 votes
2 answers
12k 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 ...
user avatar
  • 15.2k
34 votes
5 answers
17k 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?
user avatar
  • 4,591
33 votes
6 answers
29k 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 ...
user avatar
  • 388
33 votes
2 answers
20k 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 ...
user avatar
  • 15.3k
32 votes
6 answers
50k 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 ...
user avatar
  • 10.6k
31 votes
1 answer
14k views

Difference between doAfterTerminate and doFinally

Does anybody knows what is the difference between operators "doAfterTerminate" and "doFinally" in RxJava 2 ?
user avatar
29 votes
5 answers
24k 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
user avatar
  • 557
28 votes
3 answers
11k views

Which rxjava3 retrofit-adapter should we use for Rxjava3

I am using RxJava3 and retrofit but I am unable to get a rxjava3 retrofit-adapter for RxJava3.
user avatar
28 votes
2 answers
16k 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 ...
user avatar
  • 921
28 votes
3 answers
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....
user avatar
  • 1,195
28 votes
4 answers
17k 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 ...
user avatar
  • 8,809
26 votes
3 answers
15k 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 ...
user avatar
26 votes
3 answers
15k 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 ...
user avatar
  • 10.2k
25 votes
2 answers
14k 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 ...
user avatar
  • 5,225
25 votes
4 answers
3k 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: ...
user avatar
  • 10.5k
24 votes
2 answers
9k 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&...
user avatar
  • 6,185
24 votes
2 answers
4k 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(...
user avatar
  • 1,053
23 votes
4 answers
10k 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,...
user avatar
23 votes
2 answers
26k 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 ...
user avatar
  • 327
23 votes
1 answer
19k views

How to do a single row query with Android Room

How do I make a single row query with Android Room with RxJava? I am able to query for List of items, no issues. Here, I want to find if a specific row exists. According to the docs, looks like I can ...
user avatar
  • 1,620
21 votes
4 answers
18k 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> ...
user avatar
  • 2,605
21 votes
5 answers
6k 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. ...
user avatar
21 votes
7 answers
27k 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 ...
user avatar
21 votes
1 answer
14k 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 ...
user avatar
20 votes
1 answer
8k 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. ...
user avatar
20 votes
2 answers
12k 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 ...
user avatar
  • 7,850
19 votes
4 answers
19k views

Method getMainLooper in android.os.Looper not mocked still occuring even after adding RxImmediateSchedulerRule

TrendingViewModelTest @RunWith(JUnit4::class) class TrendingViewModelTest { private lateinit var trendingRepository: TrendingRepository private lateinit var trendingViewModel: ...
user avatar
19 votes
1 answer
7k views

How does backpressure work in Project Reactor?

I've been working in Spring Reactor and had some previous testing that made me wonder how Fluxes handle backpressure by default. I know that onBackpressureBuffer and such exist, and I have also read ...
user avatar
  • 297
19 votes
4 answers
8k 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 ...
user avatar
19 votes
1 answer
5k views

Paging3: "Not sure how to convert a Cursor to this method's return type" when using PagingSource as return type in Room DAO

I was trying to imitate Google's codelab for the new Paging 3 library, and I encountered the following error when I tried to have a Room DAO method return a PagingSource: D:\Programming\Android\...
user avatar
  • 1,521
19 votes
4 answers
8k 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. ...
user avatar
  • 12.6k
18 votes
1 answer
10k views

Handling Error RXJava Android with Kotlin

Hi I'm new with RxJava and Kotlin and I loose some concepts about it. I have "api" like this: interface VehiclesService { @GET("/vehicles/") fun getVehicles(): Single<List<Vehicle>&...
user avatar
  • 7,486
18 votes
2 answers
11k 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 ...
user avatar
  • 711
18 votes
2 answers
17k 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....
user avatar
  • 1,651

1
2 3 4 5
83