rx-android

Mix and match RxJava subscription threads

拥有回忆 提交于 2019-12-13 07:42:12
问题 Is it possible to mix and match scheduler threads in RxJava. Basically I want to do something like the following on Android. uiObservable .switchMap(o -> return anotherUIObservable) .subscribeOn(AndroidSchedulers.mainThread()) .switchMap(o -> return networkObservable) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> doSomething(result)) Is that possible within the same subscription ? 回答1: Yes it's possible and really easy after you have

Retrofit OutOfMemory exception while loading a files in BASE64 to server

安稳与你 提交于 2019-12-13 04:26:48
问题 I had an OOM exception when tried to load a pdf file in base64 as a field in a model throw Retrofit. I know, than this is not a normal way to upload files, but it's not a third party realisation. How I can fix this kind of a problem? An application crached when I switching off my network connection Failed to allocate a 30544558 byte allocation with 2085152 free bytes and 26MB until OOM @Streaming @POST("/api/order/") fun makeOrder(@Header("Authorization") token: String, @Body order:

converting numbers to currency format when text changes

*爱你&永不变心* 提交于 2019-12-13 03:36:32
问题 I am using RxTextView.textChanges for EditText that when the user is typing change value of EditText to convert numbers to currency format like below: 1,000 But I can't see any convert numbers to currency format . I am using from: NumberFormat.getNumberInstance(Locale.US).format(productPrice); My code is like bellow: Observable<CharSequence> observableDiscountPrice = RxTextView.textChanges(discountPriceEdittext); observableDiscountPrice.map(new Function<CharSequence, Boolean>() { @Override

How to access and increase 'rx2.buffer-size' in RxJava 2?

狂风中的少年 提交于 2019-12-13 03:26:29
问题 In http://reactivex.io/RxJava/javadoc/io/reactivex/Observable it is stated: The Observable's operators, by default, run with a buffer size of 128 elements (see Flowable.bufferSize(), that can be overridden globally via the system parameter rx2.buffer-size. My question is, how can I access and set rx2.buffer-size ? If I do: import io.reactivex.Completable; import io.reactivex.Flowable; import io.reactivex.Observable; import io.reactivex.Scheduler; import io.reactivex.Single; import io

Android: infinite scroll with rx-java using repeatWhen, takeUntil and filter with retrofit

核能气质少年 提交于 2019-12-12 20:53:42
问题 I am using Retrofit 2.2 with RxJava. The pagination works like this: I get the first batch of data, I have to request the second batch of data with the same params except one which is the lastUpdated date and then if I get empty or the same batch of data it means there are no more items. I have found this great article https://medium.com/@v.danylo/server-polling-and-retrying-failed-operations-with-retrofit-and-rxjava-8bcc7e641a5a#.40aeibaja on how to do it. So my code is: private Observable

How do I effectively read temperature from two BLE devices at the same time?

萝らか妹 提交于 2019-12-12 16:38:04
问题 First of all, I am using RxAndroidBLE library to manage my BLE connections. I have two SensorTag devices and I want to read temperature from both at the same time. For example, I'd like to read the temperature from both devices exactly every 500ms and display it to user in two TextViews. My app currently successfully connects to both BLE devices like this: @OnClick(R.id.connectButton1) public void connectFirstSensorTag(Button b) { if (!isDeviceConnected(sensorTag1)) { connectionObservable1 =

How to cancel individual network request in Retrofit with RxJava?

允我心安 提交于 2019-12-12 10:09:12
问题 I am downloading some files from the network using retrofit and rxjava. In my app, the user may cancel the download. Pseudo Code: Subscription subscription = Observable.from(urls) .concatMap(this::downloadFile) .subscribe(file -> addFileToUI(file), Throwable::printStackTrace); Now, If I unsubscribe this subscription, then all requests get canceled. I want to download one by one, that's why used concatMap. How do I cancel particular request? 回答1: There is a mechanism to cancel individual flows

how to handle RxAndroid errors in the main thread

狂风中的少年 提交于 2019-12-12 08:47:24
问题 I'm new to rxJava/Android and surprised that my onError lambda is sometimes called on the main-thread and sometimes not, although I use .observeOn(AndroidSchedulers.mainThread()) Example 1 : onError on main-thread this works as expected: onError is called on the main-thread Observable.error(new RuntimeException("RTE")) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Log.e(TAG, "onNext("+s+")-thread: " + Thread.currentThread().getName()); },

Observable.from() does not work

和自甴很熟 提交于 2019-12-12 04:06:37
问题 I am learning RxJava in Android. I am following this tutorial here: as shown in the code below, i have three observables and one subscriber. at run time, myObservable2 and myObservable2 are executed but not myObservable3. to find out why myObservable3 s not executed, I commeted out myObservable2 and myObservable2 and ran only myObservable3 and then it ran normally. why I can not run myObservable2 and myObservable2 and myObservable3 at the same time. code public class MainActivity extends

pthread_create failed: couldn't allocate 1064960-byte stack: Out of memory

假如想象 提交于 2019-12-12 03:29:01
问题 I have two fragments where inside both of these fragments, it will execute codes that utilize sqlbrite. While the app won't crash in normal usage, but the problem is, if I load these 2 fragments back-and-forth multiple times in a short period, the app will crash with this error. E/CursorWindow: Could not allocate CursorWindow '/data/data/com.imincode.meniti/databases/meniti' of size 2097152 due to error -12. E/CursorWindow: Could not allocate CursorWindow '/data/data/com.imincode.meniti