Reputation: 61
In my application I use realm database. As you know, the data is saved in objects, like this:
Allergen first_item = new Allergen();
first_item.setName("FirstItem");
first_item.setDescription("Description");
I have a list of names and descriptions, that the user can edit, delete or add. How can I store and show this data again when the user has edited this data?
Upvotes: 0
Views: 33
Reputation: 181
Initialize in MainApplication
Realm.init(getApplicationContext());
RealmConfiguration config = new RealmConfiguration
.Builder()
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(config);
Then add Below code to save.
try(Realm realm = Realm.getDefaultInstance()) {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.insertOrUpdate(first_item );
}
});
}
Upvotes: 1