Lawrence Macharia Lawrence Macharia - 1 month ago 17
Android Question

Android Realm Update Asynchronously Using RxJava

I have this query to update data already in my realm table;

for (MyGameEntrySquad squad : response.body().getSquad()) {
subscription = realm.where(RealmPlayer.class).equalTo("id", squad.getPlayer().getId())
.subscribe(new Action1<RealmObject>() {
public void call(RealmObject realmObject) {



I would like to perform this query asynchronously then display the results on the UI.

Basically, whatever is been returned by response.body().getSquad() has an id matching a record already in the DB; and that is what am using in my equalTo method.

Based on the data received, I would like to update two columns on each of the record matching the IDs.

However, I am facing a few challenges on this:

  1. The Action1 in subscribe is returning a RealmObject instead of a PlayerObject

  2. How to proceed from here

Any guidance on this will be appreciated.


realm.where(RealmPlayer.class).equalTo("id", squad.getPlayer().getId())
                        .subscribe(new Action1<RealmPlayer>() {
                            public void call(RealmPlayer player) {


You should do like that.

Btw, it's bad idea to do it in a cycle - check in method of RealmQuery.