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.

RxJava is a Java implementation of Reactive Extensions. Android-specific support for RxJava is provided by .

The main goals of RxJava

  • Stay true to the principles and concepts behind the original implementation while adjusting to the naming conventions and idioms of Java
  • All contracts of Rx should be the same target - the JVM
  • JVM-based languages supported (beyond Java itself) include , , , and
  • Support Java 6+

The library is open sourced under Apache 2.0 license.

References

6958 questions
24
votes
9 answers

How to resolve Duplicate files copied in APK META-INF/rxjava.properties

I am using rxjava and rxvolley on my android aplication. When I try to run it I get this error Execution failed for task ':testapp:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException:…
Dani Garcia
  • 464
  • 1
  • 6
  • 18
24
votes
4 answers

Handle empty response with retrofit and rxjava 2.x

When using rxjava 1.x i used to return Observable to handle empty response from retrofit: @POST( "login" ) Observable getToken( @Header( "Authorization" ) String authorization, @Header( "username" )…
Samuel Eminet
  • 4,647
  • 2
  • 18
  • 32
24
votes
2 answers

Testing endless scrolling RecyclerView with Espresso and RxJava

I have RecyclerView with endless scrolling. So when user reach last - 2 position in list, I call server for more data and during call in progress, I add one more item - progress one. Now, I'm trying to write decent UI test with Espresso which will…
Divers
  • 9,531
  • 7
  • 45
  • 88
24
votes
5 answers

RxJava timer that repeats forever, and can be restarted and stopped at anytime

In android i use Timer to execute task that repeats every 5 seconds and starts after 1 second in this way: Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { //…
MBH
  • 16,271
  • 19
  • 99
  • 149
24
votes
3 answers

Do we have any possibility to stop request in OkHttp Interceptor?

In our app we met with one special case - if our App.specialFlag == true, we need stop any request from our code. And we think, that the best approach in this situation is include special Interceptor which will stop any our requests, something like…
Pavel Strelchenko
  • 536
  • 1
  • 6
  • 19
24
votes
2 answers

Chaining requests in Retrofit + RxJava

I have 2 APIs that I want to make request to in sequence and store their data in SQLite. First I want to make request to API A and store its data in SQL table a. Then make request to API B and store its data in table b and some data in table a_b.…
Sourabh
  • 8,243
  • 10
  • 52
  • 98
24
votes
1 answer

Why RxJava with Retrofit on Android doOnError() does not work but Subscriber onError does

can someone explain me why code like this: networApi.getList() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .doOnError(throwable -> { throwable.getMessage(); …
wojciech_maciejewski
  • 1,277
  • 1
  • 12
  • 28
24
votes
2 answers

How cancel task with retrofit and rxjava

I have rest api. @Get("/serveraction") public Observable myRequest(@Query("Data") String data); I know, that okhttp has canceling functionality(by request object, by tag), but don't know how use it with retrofit and rxjava. What is the best…
zella
  • 4,645
  • 6
  • 35
  • 60
24
votes
3 answers

RxJava single background thread scheduler

I'm fairly new to RxJava so this is probably a dumb question. I am going to describe my scenario. I have some code running on the UI thread which will update some images but those images are not very important and they consume a bit of resources…
casolorz
  • 8,486
  • 19
  • 93
  • 200
24
votes
4 answers

How can I create an Observer over a dynamic list in RxJava?

I need to create an Observer over an array which is constantly changing (adding elements). I am using Obserable.from(Iterable) but it seems that it creates the Observable over the ArrayList as it is at the moment of the creation. I need the Observer…
juanpavergara
  • 1,511
  • 1
  • 11
  • 22
24
votes
4 answers

Handle Network error with Retrofit observable

When using Observables with Retrofit how do you handle Network failure? Given this code: Observable observable = api.getApiService().getMyData(); observable .doOnNext(new Action1() { @Override …
Patrick Jackson
  • 18,766
  • 22
  • 81
  • 141
24
votes
4 answers

Creating Observable from normal Java events

What is the best way to create an Rx-Java Observable from the classical Java event pattern? That is, given class FooEvent { ... } interface FooListener { void fooHappened(FooEvent arg); } class Bar { public void addFooListener(FooListener l); …
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
23
votes
2 answers

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 will go on to fetch more info from network or…
niu yi
  • 327
  • 1
  • 2
  • 6
23
votes
5 answers

Handling null in RxJava2

With the upcoming RxJava2 release one of the important changes is that null is no longer accepted as a stream element, i.e. following code will throw an exception: Observable.just(null) Honestly, I have mixed feelings about this change and part of…
Pavel Dudka
  • 20,754
  • 7
  • 70
  • 83
23
votes
1 answer

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

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…
Yoshkebab
  • 770
  • 1
  • 7
  • 14