on iOS we can easily call realm.deleteAllObjects();
to remove all objects in our Realm database.
How do we achieve the same in Android?
The right way of deleting your entire Realm (schema) is to use : Realm realm = Realm. getDefaultInstance(); realm. beginTransaction(); // delete all realm objects realm.
To delete all objects from the realm, call Realm. deleteAll() inside of a write transaction. This clears the realm of all object instances but does not affect the realm's schema.
You can do this by using results- For instance, if I want to delete all Dog objects, I can do the following-
// obtain the results of a query
RealmResults<Dog> results = realm.where(Dog.class).findAll();
// All changes to data must happen in a transaction
realm.beginTransaction();
// Delete all matches
results.deleteAll();
realm.commitTransaction();
Ref: documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With