I have a login app which uses Navigation Activity, JetPack and RoomDB. It has LoginFragment, LoginVieweModel, LoginDatabase, LoginDao and login Repository. I don't know the correct syntax to get UserCount from RoomDB.
The whole app is located in GitHub at https://github.com/msyusuf/LoginFragNavActivity.git.
Code in LoginDao is
@Query("SELECT COUNT(*) FROM loggedin_user_table")
suspend fun getLoggedInUserCount(): Int
Code in LoginViewModel is
fun getUserCount(): Int {
var count: Int = 99
viewModelScope.launch {
count = loginRepository.getUserCount()
Log.i(LOG_TAG, "In LoginViewModel.getUserCount(): count = $count")
}
return count
}
The fun getUserCount() does not have count from repository, it 99 which I used to initialize the count variable.