rx-java2

RxJava: How to multicast a Completable?

大兔子大兔子 提交于 2019-12-11 05:24:42
问题 I have a method which returns a Completable and I want it to be multicasted because any second subscriber should not re-execute the method, instead they should get the same old emitted values. I achieved it using replay().autoConnect() as follows and working as expected public Completable init() { return repository.init() .subscribeOn(Schedulers.io()) .flatMapCompletable(s -> Completable.fromAction(() -> { // some action })).toObservable().replay().autoConnect().ignoreElements(); } As you see

RxJava buffer/window with custom counting criteria

送分小仙女□ 提交于 2019-12-11 05:07:08
问题 I have an Observable which is emitting a number of objects and I want to group these objects using the window or buffer operations. However, instead of specifying a count parameter for determining how many objects should be in window I want to be able to use a custom criteria. For example suppose the observable is emitting instances of a Message class like below. class Message( val int size: Int ) I would like to buffer or window the message instances based on their size variable not just

RuntimeException thrown and not caught in RxJava2 Single after it has been disposed

落爺英雄遲暮 提交于 2019-12-11 04:59:20
问题 A RuntimeException thrown inside an RxJava2 Single is not getting caught and is not getting sent to the Observer's onError() method if the observer has been disposed. I understand that calling CompositeDisposable.dispose() means that my Subscriber's onSuccess or onError methods won't be called, but shouldn't the exception be ignored too? Instead the application is crashing because the RuntimeException isn't caught. Here is the Single, the line with the comment can throw a RuntimeException, if

Updating Activity when it comes back to the Foreground after data has already been retrieved

余生长醉 提交于 2019-12-11 03:08:45
问题 I have implemented a Service that receives notifications sent from the server. I'm currently using a broadcast receiver to send data. The Broadcast Listener is updating the Activity just fine. However, when data is sent when the Activity is not on "onResume" state, the data is not received. I got interested in using RXjava because I believe it could resolve the issue but don't know where to start. The problem: When the activity is not on the foreground , the Activity is not updating. Not in

How to create infinite interval Observable that will emit new Object every time interval?

我与影子孤独终老i 提交于 2019-12-11 00:52:33
问题 I am trying to create an Observable that will emit new object every second. So for now i am just zipping one Observable, which emits finite number of objects from a list, with interval Observable. val list1 = mutableListOf<SomeClass1>( SomeClass1("1", 1), SomeClass1("2", 2), SomeClass1("3", 3), SomeClass1("4", 4), SomeClass1("5", 5), SomeClass1("6", 6), SomeClass1("7", 7), SomeClass1("8", 8), SomeClass1("9", 9) ) val someClass1Observable = Observable .fromIterable(list1) .zipWith(Observable

RXjava and Retrofit to handle empty data response

て烟熏妆下的殇ゞ 提交于 2019-12-11 00:48:15
问题 I use Rxjava and Retrofit to handle the response from a http server. Most of the time, data response is in this format: { code: 'OK', data: {.....} } and sometimes, the data property doesn't exist. { code: 'OK' } I make a BaseResponse class. public class BaseResponse<T> implements Serializable { private String code; private String msg; private T data; public String getCode() { return code; } public String getMsg() { return msg; } public T getData() { return data; } } and make a Map function

How to properly stop rxjava Flowable?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 19:14:32
问题 I have the following code structure Service public Flowable entryFlow() { return Flowable.fromIterable(this::getEntries) } Consumer void start() { disposable = service .entryFlow() .observeOn(Schedulers.computation()) .subscribeOn(Schedulers.computation()) .subscribe( entry -> ..., this::onError, this::subscriptionFinished); } void stop() { disposable.dispose(); } private void onError(Throwable e) { subscriptionFinished(); } private void subscriptionFinished() { // } I need a way to stop the

RxJava operator Debounce is not working

[亡魂溺海] 提交于 2019-12-10 17:54:17
问题 I want to implement place autocomplete in Android application, and for this I'm using Retrofit and RxJava. I want to make response every 2 seconds after user type something. I'm trying to use debounce operator for this, but it's not working. It's giving me the result immediately without any pause. mAutocompleteSearchApi.get(input, "(cities)", API_KEY) .debounce(2, TimeUnit.SECONDS) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .flatMap(prediction -> Observable

n-ary Cartesian product inRxJava

泪湿孤枕 提交于 2019-12-10 16:54:48
问题 Now I hold an Observable<Observable<Integer> , how can I transfer it into Observable<int[]> that contains the n-ary Cartesian product? For example: Observable<Observable<Integer> ob = Observable.just( Observable.just(0,1), Observable.just(2,3), Observable.just(4,5) ); ob...... -> (0,2,4), (0,3,4), (0,2,5), (0,3,5), (1,2,4), (1,3,4), (1,2,5), (1,3,5) 回答1: First of all, you need a fixed number of input Observable s. Second, there is no need for blocking but there is likely the need for caching

Picasso + RxJava2: Method call should happen from the main thread

…衆ロ難τιáo~ 提交于 2019-12-10 15:32:54
问题 This was my initial Question: I am trying to show a few images in the AutoScrollViewPager . I am using Picasso to achieve the same. However, I would like to do the same with using Rxjava2 + Picasso. I am kinda new to this RxJava concept. So if anyone can help me with details if possible, to convert the below into RxJava code, I would really appreciate it. This is what I do in onViewCreated() imageAdapter = new ImageAdapter(getActivity()); autoScrollViewPager.setAdapter(imageAdapter);