I can add a row using RxJava with the following,
Completable.fromAction(() -> db.userDao().insert(user)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new CompletableObserver() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
});
Dao:
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insert(User user);
How can I get the row id after the DB operation?
If you want to use RxJava with Room you can change the
insert
function to return RxJava Single wrapping aLong
, like:This way you can just subscribe to this
Single
and you'll get the id as Long with something like this: