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

Is there any way to pass a Flow into a Room DAO Query method?

I'm working on implementing Room in an android app and I have a use case where I am receiving a Flow with the current user id for functionality similar to switching which logged in Google user to view a service as. I'd like to pass that flow into a…
cren90
  • 1,367
  • 2
  • 17
  • 30
2
votes
2 answers

Migration of a Date String to an Int in Android Room with Kotlin

I need to migrate my database using Room 2.3 in Kotlin 1.4.32 on Android 9.0+. In my initial database my Date is a String (i.e. "2021-06-03T22:54:15.406-07:00[America/Los_Angeles]") and I want to Migrate it to and Int (i.e. toEpochSecond) during…
2
votes
0 answers

In which part of the code in the MVVM architecture should the Room DB room be updated?

I use MVVM architecture with Room DB and LiveData in my project. When the application works offline, the data is received from roomdb, and when the user is connected to the Internet, when entering the application, the data is received as Livedata…
Mehrdad
  • 31
  • 1
  • 1
  • 4
2
votes
1 answer

PagingDataAdapter stops loading after fragment is removed and added back

I am presenting a PagingSource returned by Room ORM on a PagingDataAdapter. The RecyclerView is present on a Fragment -- I have two such fragments. When they are switched, they stop loading the items on next page and only placehodlers are shown on…
2
votes
1 answer

Room cannot verify the data integrity, versionnumber already changed

I'm frustated. I'm looking for a solution over few hours.... I've got a simple room database: @Database(entities = {User.class, Driver.class}, version = 1, exportSchema = true) public abstract class AppDatabase extends RoomDatabase { private…
2
votes
2 answers

Room + Kotlin Flow not emitting result

i'm trying to fetch some data from api, and them store on room database, so the main data source is roomDatabase. my repository code looks like: suspend fun fetchData(): Flow>> { val shouldRequestData =…
Sx67
  • 53
  • 5
2
votes
1 answer

Storing image data in Room database with or without using (typeAffinity = ColumnInfo.BLOB)

I know it's not the best practice to store an image in DB directly and we should store a path instead. But in my case this is a must. I am able to store list of images perfectly fine defined as: @ColumnInfo(name = "picture") var picture: ByteArray?…
Fatih
  • 507
  • 4
  • 15
2
votes
0 answers

Is it Ok to use singleton instead of ViewModel in case of Jetpack Compose single activity app?

There is a similar SO question, but I would like to ask specifically regarding Jetpack Compose. I have a single activity application that has a single ViewModel instance used in all composables. It works well, but now I need to add a Room db…
2
votes
0 answers

Android Studio Room & DAO: Impossible to Catch SQLiteDatabaseCorruptException

First of all, the database corruption is INTENTIONAL, it is a test for a invalid database file upload. My problem is that the exception (SQLiteDatabaseCorruptException) appears inside the DAO autogenerated java code: at…
sgm
  • 196
  • 3
  • 14
2
votes
0 answers

How to make Room ignore a field in the data model?

I am trying to run a select query on Room. I have the following Dao: @Dao abstract class TopicDao { @Query("SELECT * FROM Topic WHERE Id = :topicId") abstract fun getTopicModel(topicId: String): LiveData } the following…
M. Azyoksul
  • 1,580
  • 2
  • 16
  • 43
2
votes
1 answer

Why is a Room database initialisation synchronized?

While initialising the database using an abstract class in Rooms, the instance creation is generally done using synchronized. Why is this? return INSTANCE ?: synchronized(this) { val instance = Room.databaseBuilder( …
2
votes
1 answer

Room.databaseBuilder() cannot find Room dependencty even after importing from androidx.room.Room

Room.databaseBuilder() cannot find Room dependencty even after importing from androidx.room.Room. I have made a different Kotlin library for database and implemented dependency in gradle for Room. implementation…
saquibansari
  • 378
  • 3
  • 13
2
votes
1 answer

Update inner view inside RecyclerView item with LiveData, Room and DiffUtil

I have Message table in Room with following structure: id, text, animRes, readStatus. Then I subscribe to livedata exposed by room to display this item in recyclerview with diffutil adapter. When new message appeared in RV, animation start playing.…
2
votes
0 answers

How to set conditional based column in room db?

I am having trouble in room database. Please check my class named User. Now my query is, I dont want to update or insert single column if it comes null from API that means if "friendName (which is my one of the column)" is null from API then dont…
Arjun Solanki
  • 236
  • 1
  • 11
2
votes
3 answers

"Cannot access database on the main thread since it may potentially lock the UI for a long period of time" error on lauching coroutine

I get this error: Cannot access database on the main thread since it may potentially lock the UI for a long period of time. It happens when I launch fun turnAllWordsOn() in the ViewModel (code below). This function launches coroutine, and I thought…
1 2 3
99
100