0

I'm beginner in using sqlbrite, rxjava. So, I must run some code on a UI thread(to be specific add some markers on the map from a coursor that I have from updated db SELECT query).

Here is my starting setup:

sqlBrite = new SqlBrite.Builder().build();
resolver = sqlBrite.wrapContentProvider(mContentResolver, Schedulers.io());
Observable<SqlBrite.Query> query = resolver.createQuery(SmogContract.MeasurementEntry.CONTENT_URI, null, null, null, null, true);

However when I want to make this:

query.observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Subscriber<SqlBrite.Query>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(SqlBrite.Query query) {
                        ////add marker on a map from updated cursor select for latlng which I have in db
                        /// db is updated in some intervals from API
                }
            });

It gives me an error with AndroidSchedulers.mainThread method:

observeOn (Rx.Scheduler) in Observable cannot be applied to io.reactivex.Scheduler

In my gradle I've this in connection to sqlbrite, rxjava:

compile 'com.squareup.sqlbrite:sqlbrite:1.1.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'

And retrolambda. How to setup it properly? Without rxandroid and rxjava I'm not able to use AndroidSchedulers.mainThread().

K.Os
  • 5,123
  • 8
  • 40
  • 95

2 Answers2

1

You are using RxJava2, but SQLBrite depend on RxJava1. Because RxJava2 is a different library (rewrite not backward compatible), you have both version included in your project. I suspect you have imported io.reactivex.schedulers (from RxJava2) where your query is a RxJava1 Observable, that is observeOn need a Scheduler from rx.schedulers.

Geoffrey Marizy
  • 5,282
  • 2
  • 26
  • 29
  • to add on to this, you can go from an RxJava1 observable (which SQLBrite returns) to an RxJava2 observable with the interop library: https://github.com/akarnokd/RxJava2Interop – Anstrong Feb 21 '17 at 14:16
0

So, if anyone will be interested - now it works for me with this setup:

gradle:

compile 'com.squareup.sqlbrite:sqlbrite:1.1.1'
compile 'io.reactivex:rxandroid:1.2.1'

and the imports in my activity:

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
K.Os
  • 5,123
  • 8
  • 40
  • 95