JayVDiyk JayVDiyk - 3 months ago 16
Java Question

Delete All Realm Objects During Runtime

on iOS we can easily call

realm.deleteAllObjects();
to remove all objects in our Realm database.

How do we achieve the same in Android?

Answer

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.clear();

realm.commitTransaction()

Ref: documentation