android-room

How to store List<Object> in Room database? (I'm having trouble retrieving the list with DAO query)

五迷三道 提交于 2021-01-28 05:23:39
问题 I am storing Device objects in a Room database and I'm having a problem with retrieving one of the attributes (temp_values) that is a list of floats. I've followed other advice found on here that says you need a type converter so I've shown that here. When I try to compile I get this error: "warning: The query returns some columns [temp_values] which are not used by java.lang.Float. You can use @ColumnInfo annotation on the fields to specify the mapping. You can suppress this warning by

Restoring Room database from a local backup file, LiveData ViewModel doesn't refresh

南笙酒味 提交于 2021-01-28 03:04:36
问题 I'm trying to restore a room database programmatically. I followed this tutorial to implement a view model using LiveData of Words list, so that the words list refresh automatically on screan when insert, delete or update. mWordViewModel.getAllWords().observe(this, new Observer<List<Word>>() { @Override public void onChanged(@Nullable final List<Word> Words) { // Update the cached copy of the Ussds in the adapter. adapter.setWords(Words); } }); I also used the following code to backup and

Restoring Room database from a local backup file, LiveData ViewModel doesn't refresh

限于喜欢 提交于 2021-01-28 00:20:35
问题 I'm trying to restore a room database programmatically. I followed this tutorial to implement a view model using LiveData of Words list, so that the words list refresh automatically on screan when insert, delete or update. mWordViewModel.getAllWords().observe(this, new Observer<List<Word>>() { @Override public void onChanged(@Nullable final List<Word> Words) { // Update the cached copy of the Ussds in the adapter. adapter.setWords(Words); } }); I also used the following code to backup and

Android Room Fetch data with dynamic table name

倖福魔咒の 提交于 2021-01-27 14:46:20
问题 Is it possible to fetch data by passing the table name as a parameter ? Something like this. @Query("SELECT id, name from :tableName") fun getData(tableName: String): List<RandomModel> 回答1: Try this @Dao interface RawDao { @RawQuery List<RandomModel> getData(SupportSQLiteQuery query); } SimpleSQLiteQuery query = new SimpleSQLiteQuery("SELECT * FROM "+ tablename); List<RandomModel> models = rawDao.getUserViaQuery(query); 回答2: I think Room does not support dynamic tableName . We have two ways:

Error on room database migration test, due to a wrong “primaryKeyPosition” value

浪尽此生 提交于 2021-01-26 18:14:20
问题 I am testing a room migration and on the "migration and validation" step I got an java.lang.IllegalStateException: Migration failed. due to a wrong primaryKeyPosition value on the "service_id" column. Digging a little bit deeper I noticed that on the Expected side the attributes in the actual_visit_id_service_id_primary_key have different pk indexes (1, 2), while on the Found side, both have the same (1, 1) I checked into the database schema of table actual_visit_service in the installed app

Error on room database migration test, due to a wrong “primaryKeyPosition” value

寵の児 提交于 2021-01-26 18:09:53
问题 I am testing a room migration and on the "migration and validation" step I got an java.lang.IllegalStateException: Migration failed. due to a wrong primaryKeyPosition value on the "service_id" column. Digging a little bit deeper I noticed that on the Expected side the attributes in the actual_visit_id_service_id_primary_key have different pk indexes (1, 2), while on the Found side, both have the same (1, 1) I checked into the database schema of table actual_visit_service in the installed app

Error on room database migration test, due to a wrong “primaryKeyPosition” value

好久不见. 提交于 2021-01-26 18:09:29
问题 I am testing a room migration and on the "migration and validation" step I got an java.lang.IllegalStateException: Migration failed. due to a wrong primaryKeyPosition value on the "service_id" column. Digging a little bit deeper I noticed that on the Expected side the attributes in the actual_visit_id_service_id_primary_key have different pk indexes (1, 2), while on the Found side, both have the same (1, 1) I checked into the database schema of table actual_visit_service in the installed app

Error on room database migration test, due to a wrong “primaryKeyPosition” value

隐身守侯 提交于 2021-01-26 18:09:02
问题 I am testing a room migration and on the "migration and validation" step I got an java.lang.IllegalStateException: Migration failed. due to a wrong primaryKeyPosition value on the "service_id" column. Digging a little bit deeper I noticed that on the Expected side the attributes in the actual_visit_id_service_id_primary_key have different pk indexes (1, 2), while on the Found side, both have the same (1, 1) I checked into the database schema of table actual_visit_service in the installed app

Error on room database migration test, due to a wrong “primaryKeyPosition” value

时间秒杀一切 提交于 2021-01-26 18:08:59
问题 I am testing a room migration and on the "migration and validation" step I got an java.lang.IllegalStateException: Migration failed. due to a wrong primaryKeyPosition value on the "service_id" column. Digging a little bit deeper I noticed that on the Expected side the attributes in the actual_visit_id_service_id_primary_key have different pk indexes (1, 2), while on the Found side, both have the same (1, 1) I checked into the database schema of table actual_visit_service in the installed app

How can I perform LiveData transformations on a background thread?

允我心安 提交于 2021-01-20 15:29:10
问题 I have a need to transform one type of data, returned by a LiveData object, into another form on a background thread to prevent UI lag. In my specific case, I have: MyDBRow objects (POJOs consisting of primitive long s and String s); a Room DAO instance emitting these via a LiveData<List<MyDBRow>> ; and a UI expecting richer MyRichObject objects (POJOs with the primitives inflated into e.g. date/time objects) so I need to transform my LiveData<List<MyDBRow>> into a LiveData<List<MyRichObject>