rx-java2

RxJava2 observable take throws UndeliverableException

橙三吉。 提交于 2019-11-27 20:04:06
问题 As I understand RxJava2 values.take(1) creates another Observable that contains only one element from the original Observable. Which MUST NOT throw an exception as it is filtered out by the effect of take(1) as it's happened second. as in the following code snippet Observable<Integer> values = Observable.create(o -> { o.onNext(1); o.onError(new Exception("Oops")); }); values.take(1) .subscribe( System.out::println, e -> System.out.println("Error: " + e.getMessage()), () -> System.out.println(

Flowable concatMapSingle without prefetch to ignore clicks until processing finishes

守給你的承諾、 提交于 2019-11-27 19:36:38
问题 I want to handle clicks in such a way that they are ignored as long as I'm doing processing of some click that occurred. I thought I could do it by utilizing the backpressure, like this: private val clicks = PublishProcessor.create<Unit>() // ... clicks .onBackpressureDrop() .concatMapSingle(::handleClick, 0) But this throws an error, because there's a requirement that concatMapSingle needs to prefetch at least one item, which makes it queue the click and process it immediately after I'm done

RxJava Single.just() vs Single.fromCallable()?

一曲冷凌霜 提交于 2019-11-27 17:41:44
问题 I wondered if someone can shed some light on this question, when to use Single.fromcallable(()-> myObject) instead of Single.Just(myObject) from documents Single.formcallable /** * Returns a {@link Single} that invokes passed function and emits its result for each new SingleObserver that subscribes. * <p> * Allows you to defer execution of passed function until SingleObserver subscribes to the {@link Single}. * It makes passed function "lazy". * Result of the function invocation will be

How to chain two Completable in RxJava2

六眼飞鱼酱① 提交于 2019-11-27 15:29:15
问题 I have two Completable. I would like to do following scenario: If first Completable gets to onComplete , continue with second Completable. The final results would be onComplete of second Completable. This is how I do it when I have Single getUserIdAlreadySavedInDevice() and Completable login() : @Override public Completable loginUserThatIsAlreadySavedInDevice(String password) { return getUserIdAlreadySavedInDevice() .flatMapCompletable(s -> login(password, s)) } 回答1: You are looking for

Android RxJava 2 JUnit test - getMainLooper in android.os.Looper not mocked RuntimeException

前提是你 提交于 2019-11-27 11:19:03
I am encountering a RuntimeException when attempting to run JUnit tests for a presenter that is using observeOn(AndroidSchedulers.mainThread()) . Since they are pure JUnit tests and not Android instrumentation tests, they don't have access to Android dependencies, causing me to encounter the following error when executing the tests: java.lang.ExceptionInInitializerError at io.reactivex.android.schedulers.AndroidSchedulers$1.call(AndroidSchedulers.java:35) at io.reactivex.android.schedulers.AndroidSchedulers$1.call(AndroidSchedulers.java:33) at io.reactivex.android.plugins.RxAndroidPlugins

RxJavaPlugins Error Didn't find class “com.google.devtools.build.android.desugar.runtime.ThrowableExtension”

此生再无相见时 提交于 2019-11-27 11:09:58
问题 After upgrading Android Studio 3.0 Beta 1 getting the following error. When I downgraded the error disappeared. Studio Build: Android Studio 3.0 Beta 1 Version of Gradle Plugin: 'com.android.tools.build:gradle:3.0.0-beta1' Version of Gradle:.0.0-beta1 Version of Java: 8 OS: MacOSX java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension; at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:364) at io.reactivex

RxJava 2.x: Should I use Flowable or Single/Completable?

坚强是说给别人听的谎言 提交于 2019-11-27 10:46:31
问题 I'm developing an Android app using Clean Architecture and I'm migrating it to RxJava 2.x. I have to make some network requests to a soap service, so I defined the api interface in the domain module: public interface SiginterApi { Observable<User> login(String user, String password); ... Observable<List<Campaign>> getCampaigns(List<Long> campaignIds); } I've read that a network request should be made with " Flowable ", because of the backpressure management since it's a 'cold observable'. On

The result of subscribe is not used

元气小坏坏 提交于 2019-11-27 09:17:54
问题 I've upgraded to Android Studio 3.1 today, which seems to have added a few more lint checks. One of these lint checks is for one-shot RxJava2 subscribe() calls that are not stored in a variable. For example, getting a list of all players from my Room database: Single.just(db) .subscribeOn(Schedulers.io()) .subscribe(db -> db.playerDao().getAll()); Results in a big yellow block and this tooltip: The result of subscribe is not used What is the best practice for one-shot Rx calls like this?

When to use RxJava in Android and when to use LiveData from Android Architectural Components?

て烟熏妆下的殇ゞ 提交于 2019-11-27 04:56:26
问题 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 with sample example in the form of code which explains the differences between the both. 回答1: Android LiveData is a variant of the original observer pattern, with the addition of active/inactive transitions. As such, it is very restrictive in its scope. Using the example described in Android

Android Dagger2 + OkHttp + Retrofit dependency cycle error

旧街凉风 提交于 2019-11-27 01:53:35
问题 Hey there I am using Dagger2 , Retrofit and OkHttp and I am facing dependency cycle issue. When providing OkHttp : @Provides @ApplicationScope OkHttpClient provideOkHttpClient(TokenAuthenticator auth,Dispatcher dispatcher){ return new OkHttpClient.Builder() .connectTimeout(Constants.CONNECT_TIMEOUT, TimeUnit.SECONDS) .readTimeout(Constants.READ_TIMEOUT,TimeUnit.SECONDS) .writeTimeout(Constants.WRITE_TIMEOUT,TimeUnit.SECONDS) .authenticator(auth) .dispatcher(dispatcher) .build(); } When