Android Room database file is empty - .db, .db-shm, .db-wal Android Room database file is empty - .db, .db-shm, .db-wal android android

Android Room database file is empty - .db, .db-shm, .db-wal


Go to folder Data/data/packageName/databases/ There has to be three files .db, .db-shm, .db-wal, copy all three files to one location and then open your Myapp.db these two extra files are needed to open db file


in android studio 3.1.*

in tool window bar click on "Device File explorer" generally you can find this in bottom right corner of the screenn

open directory in data/data/your-application-package/databases

with new architecture 3 files is created in databases directory

your-database-nameyour-database-name-shmyour-database-name-wal

you have to export all 3 in the same directory

then open first one file (that is with your-database-name only ) in any sqlite browser.

and now you can see all your data .......

your-database-name-shmyour-database-name-wal

these two extra files are needed to open db fileif you will open database file only, than you will not found any table in that file


Make sure your database is closed when you exit your app, which will ensure that all outstanding transactions are committed:

@Overrideprotected void onDestroy() {    super.onDestroy();    // close the primary database to ensure all the transactions are merged    MyAppDatabase.getInstance(getApplicationContext()).close();}

Then you can copy the database off your device using the Device File Explorer in Android Studio (look under /data/data/<your app package name>/databases).

You are also able to force a WAL checkpoint instead of closing the database, but in my humble opinion this option is easier (unless you are trying to backup your database within the app programmatically or something like that) and closing databases is a good idea (even if it's not really mentioned in the Android Room documentation).

Read more about sqlite WAL here: https://www.sqlite.org/wal.html