Questions tagged [android-room]

For questions related to Android Room Persistence Library (which is a part of Android Architecture Components)

Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite.

6786 questions
2
votes
2 answers

How to update lazyColumn's item using the Flow list from room?

As below code showed, I got the list(type: Flow>), how can I use it to update lazyColumn's item, so when the room data changed, lazyColumn updates items accordingly? Many thanks. @Composable fun SomeContent(context: Context) { // get the…
caibirdcnb
  • 275
  • 5
  • 18
2
votes
1 answer

Room Database operations inside flow function

Here is my login function that return a flow override fun loginMeIn(loginDto: LoginDto): Flow> = flow { emit(Resource.Loading()) try { Log.e(TAG, "loginMeIn : try"); val result = api.loginMeIN(loginDto) …
2
votes
1 answer

Android Room Kotlin: entities with non data classes

Regarding to classes that can/may be used for entities in room whith Kotlin, Is it mandatory to use data classes? Or could I use 'normal classes', i.e., the ones I use for the 'bussiness logic' In case data classes are mandatory: can I add…
Krippulo
  • 35
  • 5
2
votes
1 answer

Android: how to insert data in manyToMany relationship in Room (Java)

Guys I'm trying to create a database with a manyToMany relationship, I'm able to create the 2 tables of elements but I'm not able to populate the joining table. I don't know how should I insert datas. This is Card.class: @Entity public class Card…
Daniele Scalco
  • 131
  • 2
  • 15
2
votes
1 answer

Difference between WorkManager and ExecutorService in android java?

I am a little bit confused on whether I should use WorkManager API provided by android or the ExecutorService which is a library by java. I am working on a MVVM java android projects and i should perform async tasks to my database and i don't know…
2
votes
1 answer

Fetch all with LiveData Room Kotlin

I am using Room in my project and I want to get list from the DB but I get null although anytime I don't use live data, I get the values so I know the data is available in the database. @Dao interface AddressDao { @Insert(onConflict =…
King
  • 1,885
  • 3
  • 27
  • 84
2
votes
2 answers

Room unique constraint failed for primary key despite autoGenerate=true

Pretty much what it says on the tin: I'm using Room 2.4.1 on Android to store some data. I have an entity which is set to have an auto-generated primary key. However, I can only do one insert of an instance of that entity (which sets the primary key…
John Chrysostom
  • 3,973
  • 1
  • 34
  • 50
2
votes
1 answer

How can I observe a table in Room and get entities from other tables based on updates?

I want to use Coroutine flows to achieve this. I have a DAO/Table in Room: info. This info-table is a lookup that holds id and type for other models. There's a table per type [A, B, C] and the id (PrimaryKey) in the info-table and corresponding…
Yokich
  • 1,247
  • 1
  • 17
  • 31
2
votes
2 answers

What should we do for nested objects in Room?

If there is a structure like my JSON structure below, how should we create Entity Classes? There are no examples of this. While @embeded was used for inner arrays in the articles written long ago, now a structure like converter is used. Which one…
user17115124
2
votes
1 answer

Even after reinstalling data is not removed in ROOM database

I have developed a simple e-commerce app, even after reinstalling I am still getting the products saved in ROOM database. I have clear data and cleared cache and reinstalled the app still I am getting the datas back. I have deleted individual data…
Rohit S
  • 714
  • 5
  • 7
2
votes
0 answers

Kotlin livedata observer not triggered

i'm practising a bit with kotlin and was testing Room and livedata, my app gets data from a json and the stores it in room, i want to move this network call to its own file and class, but if i do so the observer i set to get the changes don't…
2
votes
2 answers

What's the recommended way to update Jetpack Compose UI on Room database update?

Right now, my method of updating my jetpack compose UI on database update is like this: My Room database holds Player instances (or whatever they're called). This is my PlayerDao: @Dao interface PlayerDao { @Query("SELECT * FROM player") fun…
2
votes
2 answers

Room one-to-many, to many

I am little a bit confused on how i should set up a data class consisting of two lists. I have a data class looking like this @Entity(tableName = "recipe") data class Recipe( @PrimaryKey(autoGenerate = false) val recipeName: String, //val…
Bente61
  • 21
  • 3
2
votes
1 answer

Android ViewModel and Paging 3 Library

I am building a chat app where every data enter in room database first and it's on data insert the recyclerview get update with new data. It works as expected but now i need to update my paging library to version 3. For this i need to update these…
androidXP
  • 1,692
  • 3
  • 27
  • 58
2
votes
1 answer

Room field / getter mismatch warning when using sealed classes or Any

I have a Room (v2.4.0-beta01) database, and whilst it works fine, during the build it gives a field vs getter mismatch warning on a few fields, included below. I suspect this is due to an interop issue between Kotlin and Java, since the field…
Jake Lee
  • 7,549
  • 8
  • 45
  • 86