android - Realm with RxAndroid not picking up latest data changes -


i using realm rxandroid. having strange issue realm not picking latest modification done on db.

there 2 methods using.

observable<integer> save(bitmap bitmap). observable<integer> getimagelist(context applicationcontext). 

like this

   activity 1    getimagelist(applicationcontext)    button click -> activity 2                       save(bitmap)                       finish()       getimagelist(applicationcontext) 

this method "save" adds newly created model realmlist.

private observable<integer> save(bitmap bitmap) { return observable.create((observable.onsubscribe<integer>) subscriber -> {     --------------------------------------     -----various file creation stuff------     --------------------------------------       userimagesmodel model = realm                     .where(userimagesmodel.class)                     .findfirst();       //imagemodel class extends realmobject      imagemodel imagemodel = new imagemodel();      realm.begintransaction();     //realm object must edited inside transaction     model.getresponse().add(0, imagemodel);     realm.committransaction();      realm.close();     subscriber.onnext(1);     subscriber.oncompleted();  } } 

ans method fetches saved list.

public observable<integer> getimagelist(context applicationcontext) {     return observable.create((observable.onsubscribe<integer>) subscriber -> {         apputils.logd("user image observable instance " + this);         userimagesmodel model;         realm realm = realm.getinstance(applicationcontext);         model = realm.where(userimagesmodel.class).findfirst();           ^   model doesn't replicate data added in save call          ------------------------------------------------         ----various validation , service calls.-------         ------------------------------------------------          subscriber.oncompleted();         realm.close();     });  } } 

as mentioned in code, userimagemodel realm doesn't replicate changes made in save method.

the problem occurs when call getimagelist method second time. when print this.tostring inside observable.create prints same object returned first time.

so believe issue seems way using rxandroid. can tell me missing? , how can resolve it?

update :

after few tests realized this.tostring inside observable.create points parent object have used lamda expression not seems issue , square 1 ;(

turns out, expected behavior of realm. subscribing observables on io threads doesn't have looper.

op here has similar issue. answer explains case.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -