Sinigr Sinigr - 1 year ago 100
Java Question

Close Realm instance, when i use Realm query with RxJava

when I return query results as observable, where I must close realm instance? Example:

public Observable<RealmResults<Weather>> getWeatherForecast() {
final Realm realm = Realm.getDefaultInstance();

return realm.where(Weather.class).findAllAsync().asObservable()

Answer Source

There are a couple of cases:

  1. doOnCompleted operator:

            .doOnCompleted(new Action0() {
                 public void call() {
  2. Inside Subscriber's onCompleted method:

            .subscribe(new Subscriber<Boolean>() {
                public void onCompleted() {
                public void onError(Throwable e) {
                public void onNext(Boolean aBoolean) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download