9

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?

DiRiNoiD
  • 1,073
  • 1
  • 15
  • 20

2 Answers2

0

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

Joseph Varghese
  • 506
  • 5
  • 15
  • 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. – Ayush Jain Sep 28 '20 at 05:43
0

Please, check https://stackoverflow.com/a/63849367/3256989 . In short words, try to use enableMultiInstanceInvalidation() during building RoomDatabase.

ultraon
  • 1,630
  • 2
  • 20
  • 29