rx-java

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

MissingBackpressureException: Could not emit buffer due to lack of requests

老子叫甜甜 提交于 2021-01-29 18:58:38
问题 I've received a bug report including MissingBackpressureException: Could not emit buffer due to lack of requests for an RxJava Flowable , but I'm struggling to create a simple test case the demonstrates the problem (maintaining the structure of the Flowable ). Here's the test I'm trying to put together, which maintains the same stages in the pipeline: int inputEvents=10000; CountDownLatch completed = new CountDownLatch(1); Flowable<List<String>> flowable = Flowable.<String>create(e -> {

How to call multiple Flowable statements in parallel?

我只是一个虾纸丫 提交于 2021-01-29 18:12:55
问题 I have a few function calls that return Flowable object. I have to call this function multiple times and this function is doing some network calls. I want to do all these calls concurrently. Below is the code. Interface containing the function public Interface XYZDownstreamService { Flowable<String> getData(Request request); } Below is the Caller public List<String> getDataFromDownstreamForRequests(List<Request> requests, XYZDownstreamService service) { List<String> dataFromDownstream = Lists

RxJava combine Observable with another optional Observable with timeout

ⅰ亾dé卋堺 提交于 2021-01-29 04:32:16
问题 Asume we have two observables A and B . A publishes a result certainly, while the result from B might not be published at all (timeout). The question is how to map the result from A and B if B returns within a timeframe, otherwise just return the result from A . Observable<DatabaseObject> A = getDatabaseElement(); Observable<NetworkObject> B = restApi.getElement(); Map example: map((databaseObject, networkObject) => { databaseObject.setData(networkObject); return databaseObject; }) 回答1: In

RxJava2 - interval and schedulers

心已入冬 提交于 2021-01-28 18:58:43
问题 Let's say I have an interval, and that I've given it a computationScheduler. Like this: Observable .interval(0, 1, TimeUnit.SECONDS, computationScheduler) .flatMap { ... } Then, will everything that happens in flatmap {...} also be scheduled on a computation thread? In the sources for Observable.interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler), it says: * @param scheduler * the Scheduler on which the waiting happens and items are emitted As a beginner to RxJava, I

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

Am I using flatMap correctly to merge results from multiple API calls?

点点圈 提交于 2021-01-28 08:19:04
问题 I want to make multiple API calls (with three different queries) and merge the results and then display them in onNext() . It is working but I am concerned that flatMap is not ideal for this. @GET("www.examle.com/api/data/") Observable<WebResultsResponse> getWebResults(@Query("param1") String query); ----- private List<WebResult> resultsList; private void requestWebResults(String query) { resultsList.clear(); final Observable<List<WebResult>> observable = MainApplication.apiProvider

How to unit test “repeatWhen” in RxJava server polling

爷,独闯天下 提交于 2021-01-28 05:41:43
问题 This is my code return Observable.defer(() -> mApi.verifyReceipt(username, password)) .subscribeOn(Schedulers.io()) .doOnNext(this::errorCheck) .repeatWhen(observable -> observable.delay(1, TimeUnit.SECONDS)) .takeUntil(Response::body) .filter(Response::body) .map(Response::body); It keeps polling and receives a "false" boolean response and stops polling when "true" is received. I've made a test case for the onNext() case like: @Test public void testVerifyReceiptSuccessTrueResponse() {

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

SocketException unsubscribing request without onError

孤人 提交于 2021-01-28 03:11:51
问题 I'm trying to make a request using RxJava and Retrofit(2.3). I'm expecting that in case of any error I can retry or show a message to the client. However, I notice that sometimes I have a SocketException which results in not calling onError, apparently the subscriber of the request just unsubscribes without calling anything else (not onComplete neither onError). Anyone knows why this is happening and how can I solve this in a generic way (without simply doing onUnsubscribe() and checking if