WWW
Probably your VG has the same ID each time, so you are modifying the same object across the DB.
Obviously this is not evident from showing a partially formatted code snippet that does not resemble the issue template, nor does it actually contain the code that can reproduce your issue.
(i do not work for Realm btw, despite the contributor label)
Closing as this was answered on Stack Overflow
Hey - looks like you forgot to add a T:* label - could you please add one?
@rrreza Please understand that this repo is for tracking features and enhancements. Questions like yours really belong to Stack Overflow. This is also mentioned in the template you deleted when creating this issue.
If you think there is a problem with Realm please provide a working sample project we can look at.
That said when you are using copyToRealm it is copying the entire object replacing all fields. So why do you expect the old list to still be there when you explicitly do this: m_p.setVg(new RealmList<>(vgs.toArray(new VG[vgs.size()])));
If you only want to update some fields you should update them manually.
List<VG> vs=new ArrayList<>();
for(int i=0;i<10;i++){
VG v=new VG();
v.setId(i);
v.setName(editText1.getText().toString()+i);
Of course it "replaces VG of all previous M_P`" you are setting the ID 0...10 for every single VG you create.
Primary key uniquely identifies the object so if you insert a new object with same ID, it will overwrite the existing object with the same ID
Number currentMax = realm.where(VG.class).max("id");
int nextid = 0;
if (currentMax != null) {
nextid = currentMax.intValue() + 1;
}
vg.setId(nextid);
@cmelchior guy deleted all his posts and edited his original post to WWW.
I think this can probably be closed.