android room database locked
Asked Answered
B

2

13

I had been getting " android.database.sqlite.SQLiteDatabaseLockedException" exception from production when I had been using 3rd party non-thread safe sqlite libraries. I checked all the threads and connection closing, I made all instances singleton but I wasn't able to solve the problem (I haven't even reproduce case myself). Then I moved my orm to Room database which is completely thread safe. But I'm still getting the exactly same error from production. So isn't Room db thread safe and isn't it take care of concerns for conventional sqlite libraries as Google mentioned? Is there anybody who faces db locked error with Room?

Braw answered 8/3, 2018 at 21:36 Comment(4)
This question is impossible to ask if you don't post the code. If you get the same errore you should think about if the error is real and if it's real you probably have a problem with your implementation.Pazice
FYI facing the same issue.Carrigan
Did you get any solution for that?Gametangium
This problem disappeared for me from Crashlytics ever since updating Room to a newer version. I think it was a library issueBonny
B
0

Please, check https://mcmap.net/q/882913/-about-android-sqlite-safety-in-multi-process-case . In short words, try to use enableMultiInstanceInvalidation() during building RoomDatabase.

Bankruptcy answered 11/9, 2020 at 14:47 Comment(0)
D
-1

Try setting Journal Mode to JournalMode.AUTOMATIC. Worked fine for me.

Sample code from my project

INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                        MyDatabase.class, "myDatabase")
                        .addMigrations(MIGRATION_1_2)
                        .addCallback(sRoomDatabaseCallback)
                        .setJournalMode(JournalMode.AUTOMATIC)
                        .build();

Android Room Database Journal Mode

Diocletian answered 22/10, 2019 at 6:54 Comment(1)
As per official doc : JournalMode.AUTOMATIC is the default value when no explicit value is specified.The actual value will be TRUNCATE when the device runs API Level lower than 16 or it is a low-RAM device. Otherwise, WRITE_AHEAD_LOGGING will be used.Diphosgene

© 2022 - 2024 — McMap. All rights reserved.