Android Room Database: How to handle Arraylist in an Entity?

Type Converter are made specifically for that. In your case, you can use code snippet given below to store data in DB. public class Converters { @TypeConverter public static ArrayList<String> fromString(String value) { Type listType = new TypeToken<ArrayList<String>>() {}.getType(); return new Gson().fromJson(value, listType); } @TypeConverter public static String fromArrayList(ArrayList<String> list) { Gson gson = new … Read more

Room database migration if only new table is added

Room does NOT have a good Migration System, at least not until 2.1.0-alpha03. So, until we have better Migration System, there are some workarounds to have easy Migrations in the Room. As there is no such method as @Database(createNewTables = true) or MigrationSystem.createTable(User::class), which there should be one or other, the only possible way is … Read more

Update some specific field of an entity in android Room

According to SQLite Update Docs : <!– language: lang-java –> @Query(“UPDATE tableName SET field1 = :value1, field2 = :value2, … //some more fields to update … field_N= :value_N WHERE id = :id) int updateTour(long id, Type value1, Type value2, … , // some more values here … , Type value_N); Example: Entity: @Entity(tableName = “orders”) … Read more