Hi. Thanks for answering. Uploaded the source code here:
Dani Fujii
1

You use room in the wrong way.

class PocketViewModel(app : Application) : AndroidViewModel(app) {

fun getPockets() : MutableLiveData<List<Pocket>> {
val data = MutableLiveData<List<Pocket>>()
data.postValue(CouteDatabase.getDatabase(getApplication()).pocketDAO().getPockets())
return data
}

fun insertPocket(p : Pocket){
doAsync { CouteDatabase.getDatabase(getApplication()).pocketDAO().insert(p) }
}
}

This code creates the new database everytime CouteDatabase.getDatabase(getApplication()) .

companion object{
fun getDatabase(context: Context) : CouteDatabase {
return Room.databaseBuilder(context.applicationContext,
CouteDatabase::class.java, "coute_database.db").build()
}
}

You have to create the database only once (see App class in my project) and after this use the created instance of database. And you can return LiveData<List<>> in this case

@Query("SELECT * From pocket")
fun getPockets(): List<Pocket>
companion object{
fun getDatabase(context: Context) : CouteDatabase {
return Room.databaseBuilder(context.applicationContext,
CouteDatabase::class.java, "coute_database.db").build()
}
}
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.