Questions tagged [rx-android]
RxJava bindings for Android
rx-android
1,771
questions
258
votes
3
answers
29k
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 ...
229
votes
10
answers
70k
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 ...
122
votes
3
answers
63k
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<...
112
votes
4
answers
59k
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 ...
106
votes
6
answers
38k
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.
103
votes
8
answers
100k
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 ...
85
votes
1
answer
16k
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:
...
80
votes
3
answers
64k
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?
61
votes
11
answers
59k
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 ...
48
votes
2
answers
29k
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>...
47
votes
15
answers
20k
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 ...
47
votes
5
answers
38k
views
Retrofit API call receives "HTTP FAILED: java.io.IOException: Canceled"
Can't figure out why is this happening. Neither one of rx callbacks (onCompleted(), onError(), onNext()) not gets triggered by my call. The only thing i receive is this okhttp output:
D/OkHttp: -->...
43
votes
7
answers
57k
views
How to stop and resume Observable.interval emiting ticks
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
...
41
votes
4
answers
29k
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 ...
40
votes
3
answers
24k
views
How do I get Response body when there is an error when using Retrofit 2.0 Observables
I am using Retrofit 2.0 to make api calls that return Observables. It all works good when the call went through fine and the response is as expected. Now let's say we have an error response, it throws ...
37
votes
3
answers
30k
views
Android RX - Observable.timer only firing once
So I am trying to create an observable which fires on a regular basis, but for some reason which I cannot figure out, it only fires once. Can anyone see what I am doing wrong?
Observable<Long> ...
36
votes
1
answer
11k
views
Use RxAndroid or RxKotlin when programming in Kotlin for Android? [closed]
I am going to start using reactive programming in my Android project. I am using Kotlin as primary language and now I would like to apply Rx. My first choice was RxAndroid but then I noticed that ...
35
votes
6
answers
33k
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 ...
34
votes
1
answer
16k
views
Retrofit "IllegalStateException: Already executed"
I have a Retrofit network call that id like to run every 5 seconds. My current code:
Handler h = new Handler();
int delay = 5000; //milliseconds
h.postDelayed(new Runnable() {
public void run() {...
34
votes
5
answers
26k
views
RxJava Combine Sequence Of Requests
The Problem
I have two Apis. Api 1 gives me a List of Items and Api 2 gives me more detailed Information for each of the items I got from Api 1. The way I solved it so far results in bad Performance.
...
34
votes
3
answers
96k
views
Get the latest value of an Observable and emit it immeditely
I'm trying to get the latest value of a given Observable and get it to emit
immediately once it's called. Given the code below as an example:
return Observable.just(myObservable.last())
.flatMap(...
33
votes
3
answers
32k
views
When to unsubscribe a subscription
I have a question regarding how to unsubscribe an observable. I have two codes and I'm not really sure about which one is better.
Example 1 -> Unsubscribe the subscriber once the stream has finished:
...
31
votes
3
answers
24k
views
RxJava : How to handle error with zip operator ?
I am using RxJava and RxAndroid with Retrofit2.
Observable<ResponseOne> responseOneObservable = getRetrofitClient().getDataOne()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers....
31
votes
3
answers
9k
views
Difference between RxJava and RxAndroid?
Why do we need to use RxAndroid with RxJava? What is the functional difference between them and actual use of RxAndroid and RxJava? I can't find proper answer for this.
30
votes
2
answers
13k
views
rxjava add items after observable was created
I just started using rxjava and I got stuck. Maybe I'm not using rxjava in the right way, but I need to add items to an Observable after it was created. So I understand that You can just call ...
29
votes
2
answers
13k
views
How to handle rotation with Retrofit and RxJava/RxAndroid in Activity?
I read here that we can use some global cache in order to handle rotation.
You can prevent this by using the cache or replay Observable operators, while making sure the Observable somehow survives ...
25
votes
2
answers
6k
views
Rx 2 Android what is better Single or Observable for api calls?
when we use retrofit2 for doing API rest calls with Rx, What is the best approach to use, Single or Observable?
public interface ApiService{
Single<Data> getDataFromServer();
Observable<...
25
votes
1
answer
6k
views
Periodic HTTP Requests Using RxJava and Retrofit
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 ...
24
votes
9
answers
14k
views
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....
24
votes
5
answers
35k
views
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() {
@...
24
votes
1
answer
7k
views
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(...
24
votes
3
answers
19k
views
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 ...
23
votes
1
answer
25k
views
Process Observable on background thread
I am using RxAndroid for stream operations. In my real use-case, i am fetching a list from the server (using Retrofit). I am using schedulers to do the work on a background thread and get the final ...
23
votes
1
answer
18k
views
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, ...
23
votes
2
answers
29k
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 ...
21
votes
4
answers
32k
views
How do I handle exceptions in map() in an Observable in RxJava
I want to do this:
Observable.just(bitmap)
.map(new Func1<Bitmap, File>() {
@Override
public File call(Bitmap photoBitmap) {
//...
20
votes
1
answer
11k
views
RxJava onError Can't create handler inside thread that has not called Looper.prepare()
first i will try to explain what im trying to do, next you will see what im doing(code).
Since im new at RxJava, and still learning fell free to give me your opinion.
So, im calling a network API ...
19
votes
3
answers
9k
views
Convert AsyncTask to RxAndroid
I have the following method to post response to UI using otto and AsyncTask.
private static void onGetLatestStoryCollectionSuccess(final StoryCollection storyCollection, final Bus bus) {
new ...
19
votes
3
answers
11k
views
Using Consumer interface of Reactivex
I'm new to ReactiveX. I was learning it from reading source-code. Everything was so clear but suddenly I got this word named "Consumer" which was an Interface. It was used in place of Observer.
Can ...
19
votes
3
answers
7k
views
Rx Java mergeDelayError not working as expected
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 ...
19
votes
3
answers
4k
views
RxJava + Retrofit -> BaseObservable for API calls for centralized response handling
I am new to RxJava so please forgive me if this sounds too newbie :-).
As of now I have an abstract CallbackClass that implements the Retofit Callback. There I catch the Callback's "onResponse" and "...
18
votes
3
answers
11k
views
How can I make this rxjava zip to run in parallel?
I have a sleep method for simulating a long running process.
private void sleep() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
...
18
votes
5
answers
6k
views
Observable, retry on error and cache only if completed
we can use the cache() operator to avoid executing a long task (http request) multiple times, and reuse its result:
Observable apiCall = createApiCallObservable().cache(); // notice the .cache()
----...
18
votes
2
answers
10k
views
How to update UI from Android service using RxJava/RxAndroid
I have a Bound Service which responsible for downloading files and thus it knows the downloading status/progress. And the UI (Fragment or Activity) has to show/update download progress from the ...
18
votes
2
answers
15k
views
What is the proper way to handle subscriptions in RxJava/RxAndroid for an Activity Lifecycle?
I am just getting started on RxJava/RxAndroid. I want to avoid context leaks so I created a BaseFragment like so:
public abstract class BaseFragment extends Fragment {
protected ...
18
votes
2
answers
8k
views
Queuing tasks with RxJava in Android
I'm developing application for Android with background data synchronization.
I'm currently using RxJava to post some data on server in regular intervals.
Other than that, I'd like to provide user with ...
17
votes
2
answers
6k
views
Updating fragment from Activity Using Rxjava Android
I have a simple use case where:
Activity1 create a fragment1
fragment1 after creation notify to activity that it is created and update its activity1 views.
activity1 after getting notification update ...
17
votes
2
answers
3k
views
Why should one consider using AndroidObservables in RxJava
As i understand AndroidObservable helps ensure that :
a Subscriber always observes on the main thread
when a fragment/activity is detached/stopped, then the observation stops immediately, and ...
16
votes
4
answers
20k
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 ...
16
votes
1
answer
12k
views
RxAndroid textview events called automatically before text change events
I used rxandroid for debounce operation on an edittext search
I used
private void setUpText() {
_mSubscription = RxTextView.textChangeEvents(searchStation)//
.debounce(500, ...