rx-android

How do I handle response errors using with Retrofit and RxJava/RxAndroid?

我与影子孤独终老i 提交于 2019-12-22 10:59:46
问题 I am having trouble working out how to handle a response error with retrofit and RxAndroid. onError() gets called if there is a network error or the like but I need to be able to get the response to check if there was an authentication error. Instead what I get is a token with a null String and I can't find out why. What is the best way to go about this? This is my RxAndroid call at the moment. Client.getInstance().getService() .getToken(usernameET.getText().toString(), passwordET.getText()

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

别说谁变了你拦得住时间么 提交于 2019-12-22 04:46:10
问题 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>

Filter list of objects in RxJava

孤者浪人 提交于 2019-12-22 03:50:27
问题 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 tried different ways but I didn't find the solution. Can someone help me to do it? Here is my code: mCompositeDisposable.add( fcService.getStationList() .subscribeOn(Schedulers.io()) .flatMap( stations -> { return fcService.getSensorList(stations.get(0).getName().getOriginal()); }) .subscribe(this:

NetworkOnMainThread RxJava + Retrofit + Lollipop+

我与影子孤独终老i 提交于 2019-12-21 12:17:08
问题 I'm getting reports of a NetworkOnMainThread exception on Lollipop+ when running an https api call using Retrofit and RxAndroid . I have isolated the code and created the following example that still fails. Here's the build.gradle : apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.example.bug" minSdkVersion 9 targetSdkVersion 23 versionCode 1 versionName "1.0" }

RxJava2 filter List<Object>

て烟熏妆下的殇ゞ 提交于 2019-12-21 12:11:48
问题 I'm trying to filter a List with RxJava2 such that each item (object) in the list should pass a validation check and I get a resulting List with only items that pass that test. For instance if my Object had the following structure, class MyClassA { int value1; int value2; } I want to only get the list of items where the value2 is 10. I have an API call function that returns an Observable of List, i.e. Observable<List<MyClassA>> as follows, apiService.getListObservable() .subscribeOn

Updating fragment from Activity Using Rxjava Android

女生的网名这么多〃 提交于 2019-12-21 07:24:09
问题 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 fragment1 views. I am using rxandroid , sublibrary rxlifecycle components and android , but i am still in learning phase , there was not even rx-lifecycle tag on stackoverflow , so i am still struggling to understand the flow of this library.. Edit I prefer not to use EventBus , it's just like

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

旧城冷巷雨未停 提交于 2019-12-21 06:51:19
问题 can someone explain me why code like this: networApi.getList() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .doOnError(throwable -> { throwable.getMessage(); }) .doOnNext(list -> { coursesView.populateRecyclerView(list); courseList = (List<Course>) courses; }).subscribe(); If there is no internet goes into doOnError but throws it further so the app goes down, but code like this: networkApi.getList() .subscribeOn(Schedulers.newThread()) .observeOn

Combine RxTextView Observable and Retrofit Observable

ⅰ亾dé卋堺 提交于 2019-12-21 05:06:07
问题 As an example to getting started with RxAndroid I'm trying to implement a searchbox which triggers a rest call when the users inserts something. So far I have two working parts. The first observing the EditTextView ... RxTextView.textChangeEvents(searchEditText) .debounce(400, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<TextViewTextChangeEvent>() { @Override public void onCompleted() { Timber.d("onCompleted"); } @Override public void onError

Get the latest value of an Observable and emit it immeditely

試著忘記壹切 提交于 2019-12-21 03:29:45
问题 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(myObservable1 -> { return myObservable1; }) .map(o -> o.x) // Here I want to end up with a T object instead of Observable<T> object This does not work because by doing this the flatMap will emit myObservable1 which in turn will have to emit to reach the map . I don't know if doing such thing is even

InterruptedIOException while using Retrofit2 with rx when retryOn

喜你入骨 提交于 2019-12-20 23:20:10
问题 I'm using retrofit 2 with rx-android I have quite complex retry logic, which partially works . I cut off irrelevant code to simplify it. Here it is: public class RetryWithDelay implements Func1<Observable<? extends Throwable>, Observable<?>>, Constants { @Override public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts.flatMap(new Func1<Throwable, Observable<?>>() { @Override public Observable<?> call(Throwable throwable) { int statusCode = 500; if (throwable