How can I detect if a table has no entries using Room Persistence Library? I can't find any information on how to tackle this issue.
Create a SELECT count(*) FROM ... query that returns an int or a SELECT * FROM ... query that returns an array and check the size of the array.
simply you can make a query and check if the result is empty. Like this
this code in Dao
@Query("SELECT * FROM table ORDER BY id LIMIT 1")
LiveData<TaskEntry> loadlastTask();
then in your ViewModel class, you can call this and check
  LiveData<TaskEntry> mDBTask;
    private AppDataBase mDB;
    mDBTask = mDB.taskDao().loadlastTask();
    if(mDBTask.getValue() == null ){
    //table is empty
   }else{
     // table is not empty
   }
                        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