When does RoomDB insert data into the database? Why is my insert not getting written right away?

32 Views Asked by At

The app I'm working on inserts a row in a database and then show it on the UI. Looking at the app, I can see that the row was added since I can see it in the list once the insert is called. By the way I'm using flow in my Dao class and collect it in the UI(jetpack compose) such as

  @Query("Select from ... ")
  abstract fun getAsFlow(headerId : Long) : Flow<List<Product>>

On my app there's a functionality that copies the database to external storage. When I open the database that was copied to the external storage, the table where I inserted the row is empty. But I can see it loading in the app even if I exit the application and then reload that page.

I tried closing the connection before copying the database to external storage but that didn't work.

I guess what I want to understand the is timing when a data gets written. Because I am getting reports that the the inserted rows gets lost. How can I make sure that the rows I inserted gets written in to the database before I do the copy?

0

There are 0 best solutions below