Ad

How To Check Room Database Have Entities Or Not?

- 1 answer

I need to request to the server and pass data from my local Database whenever the app is started again. Now the problem is that when opening the app for the first time I know there are no entities how can check if Room database have entities or not?

Ad

Answer

Since you did not post any code I can only assume it works properly. You probably have an Entity object and DAO interface.

If you did everything as you needed to the data returned from the query is a List<YOUR ENTITY> and when the app is run for the first time that list should be empty. So:

if (list.isEmpty()) { do something }
Ad
source: stackoverflow.com
Ad