rx-android

When to use doOnTerminate vs doOnUnsubscribe?

主宰稳场 提交于 2019-12-07 03:30:39
问题 I need to be notified when something subscribes to my observable. I also need to be notified that the observable has either errored or completed. So I thought I should use doOnSubscribe : register an action to take when an observer subscribes to an Observable and doOnTerminate : register an action to take when an Observable completes, either successfully or with an error Then I saw doOnUnsubscribe : register an action to take when an observer unsubscribes from an Observable and thought the

AbstractMethodError when using RxJavaCallAdapterFactory on Retrofit 2

淺唱寂寞╮ 提交于 2019-12-07 03:09:29
问题 I get this error: FATAL EXCEPTION: main E/AndroidRuntime: java.lang.AbstractMethodError: abstract method not implemented at retrofit.RxJavaCallAdapterFactory.get(RxJavaCallAdapterFactory.java) at retrofit.Retrofit.nextCallAdapter(Retrofit.java:189) at retrofit.Retrofit.callAdapter(Retrofit.java:175) at retrofit.MethodHandler.createCallAdapter(MethodHandler.java:45) at retrofit.MethodHandler.create(MethodHandler.java:26) at retrofit.Retrofit.loadMethodHandler(Retrofit.java:151) at retrofit

Rxjava 2 exception with camera

喜欢而已 提交于 2019-12-07 01:15:27
问题 I just switched my code from asynctask to rxjava2 and I'm randomly getting this exception on my nexus: Camera is being used after Camera.release() was called in Galaxy s6 Edge Following is my code- Class Camera : public class Cameras { private static final String TAG = Cameras.class.getSimpleName(); private static final String SP_CAMERA_ID = "camera_id"; private static final int NO_NEXT_TASK = 0; private static final int NEXT_TASK_RELEASE_COMPLETE = 1; private static final int NEXT_TASK

RxJava/RxAndroid - handle multiple EditText changes

社会主义新天地 提交于 2019-12-07 00:21:11
问题 I have 3 EditText fields and I have created 3 observables for these fields. Observable<CharSequence> o1 = RxTextView.textChanges(field1); Observable<CharSequence> o2 = RxTextView.textChanges(field2); Observable<CharSequence> o3 = RxTextView.textChanges(field3); I want to enable a button when all these three fields has some value in it. user can enter values in any order in the fields. How can i do that? EDIT I used zip to achieve that. Observable<CharSequence> o1 = RxTextView.textChanges

Iterate list with RxJava/RxAndroid

北城余情 提交于 2019-12-06 22:24:37
问题 I'm new to RxJava/RxAndroid but I'm stuck with my use case. I try to iterate a List<A> to convert each A into an B asynchronously (because it needs call to database) and my Observer should be notified on every successful conversion (in onNext() ) to do some jobs on the main thread. I successfully managed to convert the entire list and then received my List<B> in onNext() but I need to be notified at each item, not once all items are done. I tried something with the operator from but if I use

Drop delete trigger for Room database

故事扮演 提交于 2019-12-06 17:43:24
I am using room database to store comments and RxJava as a listener to do some stuff when the database is changed. I want to not call the callback when delete is called on the table, only when insert is called. What i found out so far is that Room library has triggers that are called on delete , insert and update of the table that in turn call RxJava's methods. Is there any way to drop the delete trigger and get callbacks only for the insert and update methods? Here is my CommentDAO: @Query("SELECT * FROM comments" ) fun getAll(): Flowable<List<Comment>> @Insert(onConflict = OnConflictStrategy

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

谁说我不能喝 提交于 2019-12-06 17:19:57
问题 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() { // Here is the repeated task } }, /*Start after*/1000, /*Repeats every*/5000); // here i stop the timer timer.cancel(); this timer will repeat Until i call timer.cancel() I am learning RxJava with RxAndroid extension So i found this code on internet, i tried it and it doesnt repeat:

How to continue streaming items after error in RxJava?

送分小仙女□ 提交于 2019-12-06 15:03:46
I'm RxJava newbie, and I've got following problem. Say I have sequence of items and on of items propagates error, I want to ignore it and to continue processing other items. I have following snippet: Observable.from(Arrays.asList("1", "2", "3")) .map(x -> { if (x.equals("2")) { throw new NullPointerException(); } return x + "-"; }) .onExceptionResumeNext(Observable.empty()) .subscribe(System.out::println); I'm getting: 1- But I want to get: 1- , 3- How can I do that? the trick is to wrap the value, which would be transformed somehow, into a new observable and flatmap over it as in the

How to group by and return list in rx java

一曲冷凌霜 提交于 2019-12-06 12:07:16
问题 I'm trying to create group list based on certain conditions in Rxjava. Below is my response: { "dates":[ { "date":18, "value":"1" }, { "date":18, "value":"2" }, { "date":18, "value":"3" }, { "date":19, "value":"1" }, { "date":19, "value":"2" }, { "date":19, "value":"3" }, { "date":19, "value":"4" } ] } How can group by the values 18 [value 1, value 2, value 3, highestvalue= 3, lowestvalue = 1] 19[value 1, value 2, value 3, value 4,highestvalue= 4, lowestvalue = 1] using Rxjava Note: I can

Custom rx Func1 for retrofit response code handling

眉间皱痕 提交于 2019-12-06 11:10:50
问题 I am new in rxjava, so please don't be strict... I have request lice next one: Observable<Login>login(String l, String p){ return api.loginUser(l,p) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .flatMap(new Func1<Response<Login>, Observable<? extends Login>>() { @Override public Observable<? extends Login> call(Response<Login> r) { switch (r.code()){ case 200: requestOk(r); break; case 202: //need to Repeat login.timeout(2000,TimeUnit.Milliseconds); break; default: