Verify that all objects in the class that extends RealmObject are empty

1

My Book.class that extends 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've tried:

public boolean hasBook() {

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

But it did not work.

    
asked by anonymous 15.09.2016 / 16:04

1 answer

1

You need an instance of RealmResults to do this.

It would look like this:

RealmResults<Book> books = realm.where(Book.class).findAll();
if(books.isEmpty())
    
14.01.2017 / 19:56