rx-java2

Dagger generating multiple instances of retrofit interceptor

梦想的初衷 提交于 2019-12-20 04:43:05
问题 I am new to Dagger and Retrofit. I am having issue where multiple instances of retrofit custom interceptor are being generated despite declared singleton in dagger module. I only require one instance. Dagger Module @Module public class ApiModule { private Config config; public ApiModule(Config config) { this.config = config; } @Provides @Singleton public OkHttpClient.Builder provideOkHttpClient() { return new OkHttpClient.Builder(); } @Provides @Singleton public

RxJava 2 equivalent to isUnsubscribed

眉间皱痕 提交于 2019-12-19 09:09:34
问题 I've been working through the examples in the book Reactive Programming with RxJava, which is targeted at version 1 not 2. An introduction to infinite streams has the following example (and notes there are better ways to deal with the concurrency): Observable<BigInteger> naturalNumbers = Observable.create(subscriber -> { Runnabler = () -> { BigInteger i = ZERO; while (!subscriber.isUnsubscribed()) { subscriber.onNext(i); i = i.add(ONE); } }; new Thread(r).start(); }); ... Subscription

Difference between doAfterTerminate and doFinally

天大地大妈咪最大 提交于 2019-12-19 05:06:09
问题 Does anybody knows what is the difference between operators "doAfterTerminate" and "doFinally" in RxJava 2 ? 回答1: The difference is that doFinally executes the provided Action if the downstream cancels/disposes the sequence in addition to the regular onError or onComplete termination paths. This allows cleaning up and releasing resources by all three means. The operator also guarantees that the action gets executed exactly once per subscription even in case if the onError or onComplete

Handle empty response with retrofit and rxjava 2.x

落花浮王杯 提交于 2019-12-18 14:27:03
问题 When using rxjava 1.x i used to return Observable<Void> to handle empty response from retrofit: @POST( "login" ) Observable<Void> getToken( @Header( "Authorization" ) String authorization, @Header( "username" ) String username, @Header( "password" ) String password ); But since rxjava 2.x won't emit anything with Void is there any good practice to handle those empty responses? 回答1: Completable was designed for such cases. It available since RxJava 1.1.1. From the official docs: Represents a

Handle empty response with retrofit and rxjava 2.x

无人久伴 提交于 2019-12-18 14:24:01
问题 When using rxjava 1.x i used to return Observable<Void> to handle empty response from retrofit: @POST( "login" ) Observable<Void> getToken( @Header( "Authorization" ) String authorization, @Header( "username" ) String username, @Header( "password" ) String password ); But since rxjava 2.x won't emit anything with Void is there any good practice to handle those empty responses? 回答1: Completable was designed for such cases. It available since RxJava 1.1.1. From the official docs: Represents a

multiple api request using retrofit and rx java

雨燕双飞 提交于 2019-12-17 19:03:31
问题 I am new to android and I have a scenario where I want to get get data from multiple api. Let suppose api_a , api_b , api_c , api_d . These api are independent of each other but I want to show data from these api in a mix Recycler View ( horizontal and vertical ). So I want to make these api call in such a manner so that I can get every api data at a time so that i can display in recycler view. I already using retrofit 2 but for that I had to chain them one by one which is very lengthy and I

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

岁酱吖の 提交于 2019-12-17 08:30:31
问题 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

Retrofit2 Unauthenticated 401 error when using rxjava2

谁说我不能喝 提交于 2019-12-14 03:48:59
问题 Ever since i'v integrated RxJava2 , i am receiving 401 unauthenticated error in all retrofit calls that return Observable , i'm using basic authentication and i know error is due to it , but why it works on debug but not release. In my opinion something is wrong with the configuration for rxjava adapters of retrofit2 Stack Trace: com.jakewharton.retrofit2.adapter.rxjava2.HttpException: HTTP 401 Unauthorized 01-22 19:24:14.872 11502-11502/? W/System.err: at com.jakewharton.retrofit2.adapter

Room with Flowable: initialize database if it's empty

纵然是瞬间 提交于 2019-12-14 02:37:22
问题 I have following @Dao , that provides Flowable<User> stream: @Dao interface UsersDao { @Query("SELECT * FROM users") fun loadUsers(): Flowable<List<User>> } I want the subscriber of the stream to receive updates of the database as soon as some change happens there. Subscribing to Room's Flowable I will get that feature out of the box. What I want is following: if database is empty I want to perform a web request and save users into database. The subscriber will automatically receive new

kotlin getting a subscriber to observe an observable using RxJava2

梦想与她 提交于 2019-12-14 02:16:49
问题 Android Studio 3.0 Beta2 I have created 2 methods one that creates the observable and another that creates the subscriber. However, I am having a issue try to get the subscriber to subscribe to the observable. In Java this would work, and I am trying to get it to work in Kotlin. In my onCreate(..) method I am trying to set this. Is this the correct way to do this? class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)