2

Last time I notice that my app has a problem with SQLite database backup. To do db backup I was copying *.db file from /data/data/com.pkg.app/databases/db_name.db to internal storage. To restore I copying from internal storage to /data/data/com.pkg.app/databases/db_name.db. But in Android P There is something wrong. Those db file exists but its weight is 4kB. When I opened those file by DB Browser I noticed that file is empty - there is no tables and data. It is strange because app is working correctly. The question is where should I look for db file that my app is using? Android 8 and less has no this problem. I am using emulator.

1 Answers1

1

In Android P+ WAL (Write ahead logging) is turned on by default. This results in two additional files that suffix the original file name with -shm (shared memory file) and -wal (the write ahead logging).

These either need to be copied when backing up and restored or you need to backup only after ensuring that the database has been fully checkpointed, you can then delete the -shm and -wal files as part of the restore process.

An alternative is to disable WAL and use the less efficient journal mode.

You may wish to check out Database Import and Export not working in Android Pie.

MikeT
  • 51,415
  • 16
  • 49
  • 68