mRealm.beginTransaction();
mRealm.clear(AboutItemRealm.class);
mRealm.clear(AgendaItemRealm.class);
mRealm.clear(AttendeesItemRealm.class);
mRealm.clear(DocumentsItemRealm.class);
mRealm.clear(FAQsItemRealm.class);
mRealm.clear(GalleryItemRealm.class);
mRealm.clear(GoodToKnowItemRealm.class);
mRealm.clear(MultiEventItemRealm.class);
mRealm.clear(ReservationItemRealm.class);
mRealm.clear(SingleEventItemRealm.class);
mRealm.clear(SpeakerItemRealm.class);
mRealm.commitTransaction();
mRealm.close();
When i logout from app i need to clear data of realm for that i have to clear every class like this so is there any way to delete all data of realm without having to write all this mRealm.clear(ClassName.class) for every structure?
The right way of deleting your entire Realm (schema) is to use :
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
// delete all realm objects
realm.deleteAll();
//commit realm changes
realm.commitTransaction();
Please be aware, that this will delete all realm object that extends RealmObject class.
For updated realm transaction format
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.deleteAll();
}
});