rx-java2

Cannot resolve method Observable.from in rxjava 2

白昼怎懂夜的黑 提交于 2019-12-10 12:31:29
问题 There is a from method in the Observable class in rxjava 1 but not found in rxjava 2. How can I replace the from method in rxjava 2 in the following code: List<Integer> ints = new ArrayList<>(); for (int i=1; i<10; i++) { ints.add(new Integer(i)); } Observable.just(ints) .flatMap(new Function<List<Integer>, Observable<Integer>>() { @Override public Observable<Integer> apply(List<Integer> ints) { return Observable.from(ints); } }) 回答1: You can use Observable.fromIterable(source) From

Handling Error RXJava Android with Kotlin

假装没事ソ 提交于 2019-12-10 04:29:04
问题 Hi I'm new with RxJava and Kotlin and I loose some concepts about it. I have "api" like this: interface VehiclesService { @GET("/vehicles/") fun getVehicles(): Single<List<Vehicle>> } Then I create the retrofit client, etc.. like this: var retrofit = RetrofitClient().getInstance() vehiclesAPI = retrofit!!.create(VehiclesService ::class.java) finally I do the call: private fun fetchData() { compositeDisposable.add(vehiclesAPI .getVehicles() .subscribeOn(Schedulers.io()) .observeOn

Executing delete with room (rxjava)

。_饼干妹妹 提交于 2019-12-10 03:31:59
问题 In room the @Delete annotation doesn't emit anything. This is what the dao looks like @Dao public interface UserDao { @Delete void deleteUser(User user); //We can't use Maybe or Single or anything here } This makes it a problem while doing something like userRepository.deleteUser().subscribeOn since we have no emission coming the dao . I use the following code to call deleteUser on a background thread. Observable.just(appDatabase). subscribeOn(SchedulerProvider.getInstance().computation()).

How to convert a List<Object> to PagedList<Object> and vice-versa?

非 Y 不嫁゛ 提交于 2019-12-10 01:02:35
问题 PagedList<Object> is used for Android's cool paging library. To make the question as minimal as possible : If i have a list of strings like List<String> stringList; // it consists of 200 strings I want to convert stringList to type PagedList<String> like PagedList<String> pagedStringList; And also if i have a PagedList<Object> how can convert it to a List<Object> ? I went through this for reference If i try the other way round .... How can I convert List<Object> into DataSource.Factory

Using Realm with RxJava 2

会有一股神秘感。 提交于 2019-12-09 20:50:29
问题 I am using RxJava 2 in my Android application, and am integrating Realm. As far as I can tell, Realm only supports RxJava 1 by default, and allows an Observable to be returned when querying for RealmResults<?> , like so: Realm.getDefaultInstance() .where(VideoBundle.class) .findAll() .asObservable() .first() The Observable returned is from RxJava 1. How can I use Realm and RxJava 2 together? I have come across 2 relevant issues, found here and here, but no succinct answer was found.

Polling to Backend API in regular interval for certain number of times in a regular interval - Retrofit & RxJava

痞子三分冷 提交于 2019-12-09 19:36:29
问题 I am looking to poll the backend call for certain number of times for a predefined regular intervals. I would like to exit the loop if I have received an expected payload in between the loop and update the UI else terminate the polling. Below is the code I normally do when I make standard http call. //Response Model from backend API public class ApplicationStatusResponse { public boolean isActive; } //Retrofit facade @POST(v1/api/applicationStatus) Single<ApplicationStatusResponse>

Does RxJava2 auto dispose observable when they call completed or error?

做~自己de王妃 提交于 2019-12-08 19:51:17
问题 I have a question about the disposal on RxJava. I found this below sentence on RxSwift document on Github. When a sequence sends the completed or error event all internal resources that compute sequence elements will be freed. To cancel production of sequence elements and free resources immediately, call dispose on the returned subscription. if I understand correctly the resources (observables) will be freed after they call onCompleted or onError . So the question is, does RxJava do the same

RxJava `Completable.andThen` is not executing serially?

元气小坏坏 提交于 2019-12-08 16:07:31
问题 I have a usecase where I initiallize some global variables in a Completable , and in the next step in the chain (using andThen operator) I make use of those variables. Following sample explains my usecase in detail Say you have a class User class User { String name; } and I have an Observable like this , private User mUser; // this is a global variable public Observable<String> stringObservable() { return Completable.fromAction(() -> { mUser = new User(); mUser.name = "Name"; }).andThen

UndeliverableException while calling onError of ObservableEmitter in RXjava2

試著忘記壹切 提交于 2019-12-08 15:58:21
问题 I have a method which creates an emitter like below, there are a problem(maybe it is normal behavior) with calling onError in retrofit callback. I got UndeliverableException when try to call onError. I can solve this by checking subscriber.isDiposed() by I wonder how can call onError coz i need to notify my UI level. Addition 1 --> RxJava2CallAdapterFactoryalready implemented private static Retrofit.Builder builderSwift = new Retrofit.Builder() .baseUrl(URL_SWIFT) .addCallAdapterFactory

How to merge several objects into a single one after execute the groupBy operation?

家住魔仙堡 提交于 2019-12-08 09:39:01
问题 I have the class below that I've created to illustrate my doubt. After doing the initial transformations on my flowable I have: UserScoreTO{id=1, name='john', score=4} UserScoreTO{id=1, name='john', score=5} UserScoreTO{id=1, name='john', score=1} UserScoreTO{id=2, name='paul', score=4} UserScoreTO{id=2, name='paul', score=2} UserScoreTO{id=3, name='mark', score=1} UserScoreTO{id=3, name='mark', score=7} I want to combine UserScoreTO objects with the same id into a Flowable that emits one