Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all records from realm object without fetching it in android?

Tags:

android

realm

I have 1 realm object and some records inside it. I want to make the object having empty records without fetching it, in a single transaction.

RealmResults<Movie> movies = realm.where(Movie.class).findAll();
movies.deleteAllFromRealm();

Now we have like this but I want something like the following without the first line.

realm.deleteAll(Movies.class);

Is there anything like this? I don't know, may be it will take less time to delete. I am just worried about the time it is taking to delete. In my application I have 10 objects having more than 200,000 records.

like image 404
Ratikanta Avatar asked Dec 14 '16 06:12

Ratikanta


People also ask

How do I delete all data from a realm?

The right way of deleting your entire Realm (schema) is to use : Realm realm = Realm. getDefaultInstance(); realm. beginTransaction(); // delete all realm objects realm.

How do I save my realm data?

To save data from Realm Studio: Go to File > Save data and select JSON or Local Realm.


1 Answers

realm.executeTransaction(new Realm.Transaction() {
    @Override
    public void execute(Realm realm) {
        realm.delete(Movies.class);
    }
});

In older Realm versions, it was called Realm.clear(Movies.class);.

like image 163
EpicPandaForce Avatar answered Oct 30 '22 18:10

EpicPandaForce