rx-java2

How to unsubscribe to an RXjava call in a broadcast receiver

被刻印的时光 ゝ 提交于 2019-12-14 02:05:25
问题 I am using RXJava2 to send email within a broadcast receiver and I would like to know when I should unsubscribe to the event. The code is basically: getSmsMmsObservable() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnError(throwable -> Timber.e(throwable, "Error sending mail.")) .map(smsMmsAddress1 -> { smsMmsAddress = smsMmsAddress1; return doInBackgroundSendEmail(); }) .map(stringSingle -> { mMsgResponse = stringSingle; this.done = true; return deleteFile();

Why i have undesired Log output when merging 2 observables into other Observable, which buffers them every 10 seconds

為{幸葍}努か 提交于 2019-12-13 23:30:19
问题 I am trying to simulate merging 2 different Observable streams, which are emitting some object every second. This object has the same Parent in those 2 streams. I thought, that in the console will appear new object with value after 1 second. However, when i print those objects, i get objects that skipped the previous emission. So like object with value 1, 3, 5, 7 etc. However, in the buffer, which merges those two it seems that it only buffer the 2, 4, 6, 8 etc. emissions. Here is my code:

RxJava buffer until changed

孤者浪人 提交于 2019-12-13 17:12:13
问题 I have an observable which emits large number of data like [1,1,1,2,2,2,3,3,1,1,5,5......] In RxJava we can use distinctUntilChanged() to get a distinct items until it changed and it would result like [1,2,3,1,5,......] Similarly is there a way to buffer the items until changed? for example I expect an output like [[1,1,1] , [2,2,2] , [3,3] , [1,1] , [5,5]......] 回答1: You can share the source sequence, apply distinctUntilChanged to one path which will then drive a buffer operator that uses an

RxJava. Sequential execution

南笙酒味 提交于 2019-12-13 11:37:33
问题 In my Android App I have a presenter which handles user interactions, contains kind of request manager and if needed sends user input over request manager to request manager. Request manager itself contains server API and handles server request using this RxJava. I have a code, which sends a request to server everytime a user enters a message and show the response from server: private Observable<List<Answer>> sendRequest(String request) { MyRequest request = new MyRequest(); request.setInput

Realm access from incorrect thread in rx and dagger

早过忘川 提交于 2019-12-13 04:46:04
问题 I know this question asks a lot but i am confused by reading this question.In my project i am using dagger, rx and realm in mvp pattern.I have an application with a LoginActivity that when the user login correctly, the user information that comes from server store in realm in this page and user jumps to MainActivity.In MainActivity i want this user info but i got this error: java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread

how to get a key from rxjava insert query in vert.x

爷,独闯天下 提交于 2019-12-13 03:55:56
问题 I have an insert method in my vert.x project written in rxjava style. In my method I run an insert query to insert the record in ms sql server. I want to get the auto incremented key of newly inserted record. How I can get it? Here is my code. @Override public Single<Record> save(Record record) { return new AsyncResultSingle<Record>(resultHandler -> { jdbcClient.rxGetConnection() .subscribe(connection -> { String sql = "INSERT into record (ani, template_id) values (?, ?)"; JsonArray params =

Parse data from OpenWeatherMap, using retrofit2 and rxJava2

不想你离开。 提交于 2019-12-13 03:34:52
问题 I've started to learn Retrofit and RxJava, and I've decided to create weatherApp. Now my goal is to retrieve weather data from OpenWeatherMap Api. Here's my code: For api: package com.example.aldres.workingwithapis.Api; import com.example.aldres.workingwithapis.models.WeatherData; import retrofit2.http.GET; import retrofit2.http.Query; import rx.Observable; public interface Api { @GET("weather?") Observable<WeatherData> getWeatherData(@Query("q") String city); } Also code for my WeatherData

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

How to insert data and get id as out parameter in android room and rxjava 2?

假装没事ソ 提交于 2019-12-12 19:37:27
问题 Insert query @Insert(onConflict = OnConflictStrategy.REPLACE) long insertProduct(Product product); //product id is auto generated view model public Completable insertProduct(final String productName) { return new CompletableFromAction(() -> { Product newProduct = new Product(); newProduct.setProductName(productName); mProductDataSource.insertOrUpdateProduct(newProduct); }); } In activity where I called this above function I used CompositeDisposable. CompositeDisposable mDisposable = new

How to Transform Observable<Observable<List<T>>> to Observable<List<T>>

ε祈祈猫儿з 提交于 2019-12-12 17:52:14
问题 I am stuck on how to convert/transform the following observable type to my target type: I have observable of type: Observable<Observable<List<FooBar>>> I want to convert it to: Observable<List<FooBar>> So when I subscribe on it, it emits List<FooBar> not Observable<List<FooBar>> I tried with map, flatMap... I could not find a solution. However, I found a strange looking operator called blockingFirst which my IDE indicates that it returns Observable<List<FooBar>> when applied to Observable