Reputation: 7527
I am using Realm along with RxJava and at the end i want to fetch an observable that i can use:
@Override
public Observable<List<Data>> getData_List() {
final Observable<RealmResults<Data>> observable
= realm.where(Data.class).findAll().asObservable();
}
This is my current code, as of now i get an error saying that they are incompatible types, ie observable is io.reactivex.Observable
whereas what the Realm returns is of type rx.Observable<io.realm.RealmResults<E>>
.
What i want to do is query the realm database and return an Observable list of data objects (Observable<List<Data>>
).
How can i do this?
Upvotes: 1
Views: 377
Reputation: 81568
In order to convert RxJava1 Observable into RxJava2 Observable, you can use RxJava2Interop library using RxJavaInterop.toV2Flowable(rx.Observable);
.
Upvotes: 1
Reputation: 2487
asObservable()
method returns RxJava1.x types and has been deprecated. Since you are using RxJava2, types don't match. See this github issue for more information.
Upvotes: 1
Reputation: 245
You can use toList() operator to achieve this. RealmResults are just the cursor or pointer to the database and they cannot be used as list directly. Follow this blog if you want to know more about toList.
http://tomstechnicalblog.blogspot.com/2015/11/rxjava-operators-tolist.html
Upvotes: -1