How to correctly check if a record exists? In my case I get the error message.
In Fragment:
GroupDao groupDao = AppDatabase.getInstance(requireContext()).groupDao();
if (groupDao.isGroupExists(0)) {
//
}
GroupDao:
@Query("SELECT EXISTS(SELECT * FROM group_table WHERE id = :groupId)")
Boolean isGroupExists(Integer groupId);
Error:
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.