rx-android

How pass data between activities using RxJava in android?

谁说我不能喝 提交于 2021-02-04 17:33:09
问题 I need to pass some data between two activities MainActivity and ChildActivity . Button click on MainActivity should open ChildActivity and send event with data. I have singleton: Subject<Object, Object> subject = new SerializedSubject<>(PublishSubject.create()); and in MainActivity I have the following button click handler: public void onClick(){ startActivity(new Intent(MainActivity.this, ChildActivity.class)); subject.onNext(new SomeEvent(data)); } and event listener subscription in

RxJava: how do you flush a timed buffer?

ⅰ亾dé卋堺 提交于 2021-01-28 08:46:00
问题 I'm creating this PublishProcessor that save to the database its element every 10 seconds: val publishProcessor = PublishProcessor.create<Entity>() publishProcessor .buffer(10, SECONDS) .observeOn(Schedulers.io()) .subscribe( { saveToDatabase(it) }, { Log.e("TAG", "Error: $it") }) .addTo(compositeDisposable) When my activity finish, I want to flush everything that is in the current buffer, and not wait 10 seconds. How do I do that? 回答1: Have another subject as the buffer boundary that is

Download Image via Glide with rxJava

爱⌒轻易说出口 提交于 2021-01-28 05:22:09
问题 I need to download pictures (Bitmaps) via a given url. As I use Glide in my project to display the pictures I thought I could simply use their mechanism to download the pictures as well. I need to use it in a RxJava Environment and my problem is that the callback onResourceReady() is not called and of course the methods subscriber.onNext() and subscriber.onCompleted() are not getting called either. I get an IllegalStateException (see below). I guess the call to Glide needs to be done on the

RxJava: how to handle combineLatest() when one of the streams emits nothing

痞子三分冷 提交于 2021-01-27 13:21:08
问题 I use combineLatest() to combine 3 streams of observables. All these are combined so that all data in the UI is shown at the same time. Now, there is a scenario in which one of the observables won't emit anything, since the data that gets fetched, can be null. Is there a RxJava operator to let the subscriber know that there won't be any emits because of null data? Edit private fun retrieveData() { Observable.combineLatest(getCurrentUser.execute(), getLatestGoal.execute(), getLatestLog.execute

How can I continue Rx chain different ways based on the property?

拥有回忆 提交于 2021-01-07 01:27:53
问题 I have a method where based on Flowable data value I need to continue RX chain different ways . what I mean is that if the isOnline property of data object is true then I need to call scan(initial,selector) but if it is false then I need to call scan(selector) @NotNull public Flowable<Data> initialCall( @NotNull Flowable<Info> info, Data initial) { return info .map() .switchMap(it -> call(Flowable.just(it),initial, it.isOnline)); } private Flowable<Data> call ( Flowable<A> a, Data initial,

RxAndroid download multiple files, max 3 concurrent thread

此生再无相见时 提交于 2020-06-27 04:04:29
问题 I have api to download single mp3 file from server,which is consumed using RxJava as bellow. Observable<ResponseBody> observable = audioService.getFile(fileNameWithExtension); observable.subscribeOn(Schedulers.newThread()) .observeOn(Schedulers.newThread()) .subscribe(someCallBackClass<ResponseBody>); This just downloads single file , callback saves the file on disk. I want to download list of files save each file on disk and wait till all download completes , At max 3 calls should be

RxJava flatMapIterable with a Single

这一生的挚爱 提交于 2020-05-10 03:42:25
问题 I'm trying to tidy up my code a little, and Single is looking like a good choice for me as I'm doing something that will only ever emit one result. I'm having an issue though as I was using flatMapIterable previously to take my response (a list) and do something on each item. I'm not seeing how I can achieve this with Single. getListOfItems() .flatMapIterable(items -> items) .flatMap(item -> doSomethingWithItem()) .toList() This works fine if getListOfItems is returning an Observable but if I

RxAndroidBle Multiple Characteristic Notifications and Read/Write

笑着哭i 提交于 2020-04-14 08:14:52
问题 I'm having issues setting up notifications on multiple characteristics. I've reviewed the documentation and many of the examples only cover very granular situations. My use case is as follows: 1. scan for devices 2. user selects device to connect to (with the connection persisting until the app is closed) 3. subscribe to notifications for many characteristics 4. read/write to either single characteristics at a time, and in some cases read/write to many characteristics at a time 回答1: I got it

Retrofit Call enqueue method or Rxjava

别等时光非礼了梦想. 提交于 2020-03-13 06:21:50
问题 As Retrofit docs represent Call enqueue method in Retrofit is : Asynchronously send the request and notify callback of its response or if an error occurred talking to the server, creating the request, or processing the response. and Rxjava according to this tutorial is : RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming it seems these two have the same approach. What is advantages and disadvantages of each? Which one is