Check that all objects in the class that extends Realmobject are empty

Asked

Viewed 40 times

1

My Book.class extending realmobject

public class Book extends RealmObject {
    private String title;
    private String author;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }
}

How do I find out if these objects are empty?

I tried to:

public boolean hasBook() {

    return !realm.allObjects(Book.class).isEmpty();
}

But it didn’t work.

1 answer

1

You need an instance of Realmresults to do this check.

It would look like this:

RealmResults<Book> books = realm.where(Book.class).findAll();
if(books.isEmpty())

Browser other questions tagged

You are not signed in. Login or sign up in order to post.