javaandroidrx-javarx-java3rx-java-completable

Insert in Room database missing values


I am using RxJava to do the background task and using java, android and its an old project. I am inserting the values in OnComplete in CompletableObserver which is in background thread inside a foreground service. After the insertion operation the foreground service is stopped.

Now the problem is I have an arrayList having suppose 75 items, I have tried inserting the values one by one in loop or by inserting all at once but later when I am opening the Db file in sqlite browser its showing less values most of the time random like sometimes 47 items are inserted, sometimes 10 etc. I have tried giving delay after insert, didn't work, also tried using different conflict strategies but didn't work either. My primary key is always unique, is there any possibility that room checks other object items for uniqueness. I have tried to copy the List data and create a json file in my internal storage, it working and all data are showing. Couldn't figure out why this is happening with this Room Db. Any help/guidance would be great


Solution

  • The problem is fixed. I was actually saving the db file and opening it with sqlite browser. Closing the Room Db is important in this case as unless we close db it might be possible that it remains on cached db. But we shouldn't worry about that because it would always provide data from db anyway, but always remember to close db (RoomDatabase.close() where RoomDatabase is from Room.databaseBuilder()), then save and check the db file in any browser. It would be helpful to anyone and maybe my future self :)