rx-java

Why does thread changed to Main thread in callback?

青春壹個敷衍的年華 提交于 2020-03-05 00:30:33
问题 I am developing an android app using the Kotlin and RxJava. I developed In-App billing using the android latest API. But the library only support async callback. So I make a code like: private fun consumePlayStore(consumeParams: ConsumeParams, secKey: String, purchase: Purchase): Single<Pair<String, Purchase>> { return Single.create<Pair<String, Purchase>> { emitter -> Log.d("TEST", "[Billing] consumePlayStore") // IO Thread // Google InApp Library call playStoreBillingClient?.consumeAsync

Canonical way to convert Completable to Single?

别等时光非礼了梦想. 提交于 2020-02-24 11:04:14
问题 I have an RxJava Completable that I want to execute, then chain to a Single<Long> . I can write it like this: return Completable.complete().toSingleDefault(0L).flatMap { Single.just(1L) } but this seems unnecessarily complicated. I would have thought Completable#toSingle() would do the job, but if I write: Completable.complete().toSingle { Single.just(1L) } I get errors. Is there a missing function in Completable or am I overlooking something? 回答1: You probably want to use the andThen opeator

Debouncing button clicks using Rx

岁酱吖の 提交于 2020-02-23 09:37:05
问题 I'm trying to make a simple "button debouncer" which will count filtered clicks and display it thru a TextView. I want to filter rapid/spam clicks in a way that clicks with less than 300ms time-gap in-between are ignored. I did my research and stumbled upon Rx 's awesome debounce() which in theory should do the exact thing I wanted.. ..or so I thought. As the app seemed to only register the first click; the counter won't increment no matter how long I tried to wait. Here's a piece of my code:

mActivity from Fragment.onAttach() not retained

风格不统一 提交于 2020-02-08 09:10:37
问题 I have setup a Observable/Subscriber with RxJava. The Observable is created in MainActivity. The Subscriber is a android.support.v4.app.Fragment called MyFragment. The Observable gets data from RESTful service and stores the data in a SQLite db on the device. This works. When its work is done, which takes 4 or 5 seconds such that MyFragment has already processed onCreate() , onCreateView() etc., the subscriber, MyFragment, is notified via its implemented onNext() method (this works) and is

mActivity from Fragment.onAttach() not retained

不问归期 提交于 2020-02-08 09:09:08
问题 I have setup a Observable/Subscriber with RxJava. The Observable is created in MainActivity. The Subscriber is a android.support.v4.app.Fragment called MyFragment. The Observable gets data from RESTful service and stores the data in a SQLite db on the device. This works. When its work is done, which takes 4 or 5 seconds such that MyFragment has already processed onCreate() , onCreateView() etc., the subscriber, MyFragment, is notified via its implemented onNext() method (this works) and is

UI blocking occurs in Android despite RxJava

蓝咒 提交于 2020-02-04 07:11:24
问题 I am using RxJava to move network access to a separate thread in Android, but my UI still blocks. I am not using the wrong observable as shown here: Android RxJava, Non Blocking? The codepoints [A], [B] and [C] in below code are passed in the order [A] -> [C] -> [B] so the current thread is processed fine and RxJava calls [C] once it had a result. This is fine. Also, blocking is much better compared to doing the network call on the UI thread, but I still have minor blocking. The UI stays

UI blocking occurs in Android despite RxJava

妖精的绣舞 提交于 2020-02-04 07:10:36
问题 I am using RxJava to move network access to a separate thread in Android, but my UI still blocks. I am not using the wrong observable as shown here: Android RxJava, Non Blocking? The codepoints [A], [B] and [C] in below code are passed in the order [A] -> [C] -> [B] so the current thread is processed fine and RxJava calls [C] once it had a result. This is fine. Also, blocking is much better compared to doing the network call on the UI thread, but I still have minor blocking. The UI stays

UI blocking occurs in Android despite RxJava

こ雲淡風輕ζ 提交于 2020-02-04 07:10:08
问题 I am using RxJava to move network access to a separate thread in Android, but my UI still blocks. I am not using the wrong observable as shown here: Android RxJava, Non Blocking? The codepoints [A], [B] and [C] in below code are passed in the order [A] -> [C] -> [B] so the current thread is processed fine and RxJava calls [C] once it had a result. This is fine. Also, blocking is much better compared to doing the network call on the UI thread, but I still have minor blocking. The UI stays

RxJava Observable buffer based on content

佐手、 提交于 2020-02-04 04:57:11
问题 I started a project using vertX and RxJava, and I have a problem for which I don't find a solution. I have an Observable that emits WebSocketFrame for incoming communications, each WebSocketFrame is composed of a payload (a ByteBuffer) and flags that indicates wether it is the first frame of the message or the last. I want to make an operation on this Observable to transform it to an Observable that emits ByteBufferd that contain all the frame of a each message. I tried the buffer method but

How to concatenate two observable operations in a linear fashion (do first this thing and after that one finishes do the second thing)?

╄→гoц情女王★ 提交于 2020-02-03 08:27:08
问题 Polidea has released a new handy library called RxAndroidBle which is very useful for dealing with a lot of issues when you're using vanilla Bluetooth APIs. Before explaining more the idea is to have a POJO model that has all the recent values that the device send (or I query) to me (in this case is represented by a Map object): If I want to be notified about multiple characteristic notifications I can do this: final UUID serviceUuid = // your service UUID final Map<UUID, byte[]> genericModel