Data change in realm android -


in android app, persist workout object realm. in 1 of activities, create object code:

                    realm.begintransaction();                      workout w = realm.createobject(workout.class);                      w.setmworkoutid(uuid.randomuuid().tostring());                      realm.committransaction(); 

here workout class:

public class workout extends realmobject { private string mworkoutid;  private int restsecsleft;  private boolean prevsetover = true; private boolean workoutover = false;  public workout() {  }  public string getmworkoutid() {     return mworkoutid; }  public void setmworkoutid(string mworkoutid) {     this.mworkoutid = mworkoutid; }    public int getrestsecsleft() {     return restsecsleft; }  public void setrestsecsleft(int restsecsleft) {     this.restsecsleft = restsecsleft; }    public boolean getprevsetover() {     return prevsetover; }  public void setprevsetover(boolean prevsetover) {     this.prevsetover = prevsetover; }   public boolean getworkoutover() {     return workoutover; }  public void setworkoutover(boolean workoutover) {     this.workoutover = workoutover;     }  } 

i have service runs after workout created, , after debugging odd behavior, have found instance value of "prevsetover" saved in workout realmobject different value returned w.getprevsetover(). not sure how happening--i not change value of variable prevsetover after object instantiated. new realm user , not understand how happening. picture have attatched screenshot of w.prevsetover() method , realmobject having different values.

there more variables in debugger in screen, left of them out in post simplicity's sake.

enter image description here

it right behaviour of realm.

realm generates proxy object inherit workout when compiling. , read/write data from/to realm implemented proxy object through overriding getters/setters. original object's member field won't changed realm.

when realm.createobject() called, return proxy object, member fields not expected.

you still can create instance of original model object call standalone object (means not managed realm) calling workout w = new workout(). act normal java object. , still can copy realm calling w = realm.copytorealmorupdate(w). notice changed w's value return value. function return proxy object managed realm now.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -