rx-android

Schedulers.io() not returning to main thread

孤者浪人 提交于 2019-12-05 13:05:36
I'm using RxParse to parse query's async load but when i subscribe my observable using subscribeOn(Schedulers.io()) my onCompleted method is never called on main thread. Instead of this, my onCompleted method is called inside of worker thread pool. If i use observeOn(AndroidSchedulers.mainThread) everything will work as well, but my onNextMethod will be called on main thread too and I don't want it. There is something wrong in my code? Have anything wrong in my code? ParseObservable.find(myQuery) .map(myMapFunc()) .subscribeOn(AndroidSchedulers.handlerThread(new Handler())) .subscribe( new

What is the MutableLiveData equivalent in RxJava?

被刻印的时光 ゝ 提交于 2019-12-05 10:31:40
Per the example below from the LiveData Android documentation, what would be the RxJava 2 equivalent? We certainly can use a combination of publish() , refcount() and replay() to achieve the core of the MutableLiveData observable behavior. That said, what would be the analogous counterpart of mCurrentName.setValue() as it pertains to detecting a change and emitting the corresponding event? public class NameViewModel extends ViewModel { // Create a LiveData with a String private MutableLiveData<String> mCurrentName; public MutableLiveData<String> getCurrentName() { if (mCurrentName == null) {

Get JSON object one by one from JSON array in Android using Retrofit and RxJava

安稳与你 提交于 2019-12-05 09:47:58
I am using retrofit to hit my network api which returns json array. I am doing so using following code- Observable<MyJson[]> response = (Observable<MyJson[]>)mNetworkService.getReadyObserverable(mNetworkService.getNetworkServiceApi().getMyDataJsons(), MyJson.class, true, useCache); mAirlineSubscription = response.subscribe(new Observer<MyJson[]>() { @Override public void onCompleted() { Log.d(TAG, "getData completed.."); } @Override public void onError(Throwable e) { Log.e(TAG, "onError: " + e.getLocalizedMessage()); } @Override public void onNext(MyJson[] myJsonData) { //I want here json data

When to use doOnTerminate vs doOnUnsubscribe?

ぐ巨炮叔叔 提交于 2019-12-05 08:19:14
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 symmetry of doOnSubscribe / doOnUnsubscribe would be better. So, will doOnTerminate always be called

AbstractMethodError when using RxJavaCallAdapterFactory on Retrofit 2

浪尽此生 提交于 2019-12-05 08:05:35
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.Retrofit$1.invoke(Retrofit.java:132) at $Proxy0.getPosts(Native Method) when trying to use

Rxjava 2 exception with camera

∥☆過路亽.° 提交于 2019-12-05 05:46:52
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_SWITCH_COMPLETE = 2; private static final int NEXT_TASK_START_PREVIEW = 3; private Camera camera; private

How to emit items from a list with delay in RxJava?

喜你入骨 提交于 2019-12-05 05:33:17
I'm using Retrofit to get bookmarks from REST API: public interface BookmarkService { @GET("/bookmarks") Observable<List<Bookmark>> bookmarks(); } Now I would like to emit each item from this list with delay. I did something similar to this in Java, but onCompleted is never triggered. private Observable<Bookmark> getBookmarks() { return getBookmarkService().bookmarks() .flatMap(new Func1<List<Bookmark>, Observable<Bookmark>>() { @Override public Observable<Bookmark> call(List<Bookmark> bookmarks) { Observable<Bookmark> resultObservable = Observable.never(); for (int i = 0; i < bookmarks.size()

Executing delete with room (rxjava)

孤者浪人 提交于 2019-12-05 04:08:01
In room the @Delete annotation doesn't emit anything. This is what the dao looks like @Dao public interface UserDao { @Delete void deleteUser(User user); //We can't use Maybe or Single or anything here } This makes it a problem while doing something like userRepository.deleteUser().subscribeOn since we have no emission coming the dao . I use the following code to call deleteUser on a background thread. Observable.just(appDatabase). subscribeOn(SchedulerProvider.getInstance().computation()). subscribe(db -> { userRepository.logoutUser(loggedUser.getLoggedInUser()); loggedUser.setLoggedInUser

RxJava/RxAndroid - handle multiple EditText changes

此生再无相见时 提交于 2019-12-05 03:31:10
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(field1); Observable<CharSequence> o2 = RxTextView.textChanges(field2); Observable<CharSequence> o3 =

Android manage multi request rxJava on rotation device

若如初见. 提交于 2019-12-05 03:28:54
I'm using MVVM on android application and i want to manage requests and rxJava on device rotation, how can i disable request after rotation device and countinue from last request? this is my simple code to know how can i doing that, but i can't find any document and sample code about it @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_register); ... Observer<String> myObserver = new Observer<String>() { @Override public void onError(Throwable e) { // Called when the