Skip to content Skip to sidebar Skip to footer

How To Get A Specific Entity In Room

So, I'm using Room database to store courses and I'm stuck on the method that returns the course with the name(course) that I want because it's always returning null. I have dimin

Solution 1:

Read documentation, liveData will always return null for straight call, you have to observe LiveData, the result value from Room will be in block. This is some example of usage

mViewModel.getAllUsers().observe( this@YourActivity, Observer {
        // it - is all users from DB
    })

but if you will call

val users = mViewModel.getAllUsers()

the result will be null

Post a Comment for "How To Get A Specific Entity In Room"