Search code examples
androidsqliteandroid-sqlitedb-browser-sqlite

if I update the database by DB Browser, it does not change in my app


I have an SQLite database which I created by using DB Browser, I putted it in assets file and I use SQLiteAssetHelper to access it. Why if I update any record using DB Browser It dose not change in my app ?!
Also If I execute insert query in my app, the new record does not appear in DB Browser.


Solution

  • You're dealing with 3 different databases:

    1. The database you create with DB Browser and is stored in a folder in your pc.

    2. The database in assets folder which is a copy of the database you created with DB Browser

    3. The database in your emulator/device that was created the 1st time you ran the app.
      This last database originally was a copy of the database you had in assets folder.

    When you make changes to the database in case 1, these changes are not reflected to either the database in assets folder or in your emulator/device.
    If you want these changes to be made to your emulator/device database, you must:

    • Delete the database from assets and copy there the changed DB Browser database.
    • Uninstall the app from the emulator/device so the database is deleted.
    • Run the app again, so the database is recreated in the emulator/device.

    When you make changes to the emulator/device and you want to examine the database with DB Browser:

    • In Android Studio select View > Tool Windows > Device File Explorer
    • In the Device File Explorer window go to data/data/yourpackagename/databases folder and right click your database and click Save as.... Select the folder where you want the database to be saved and you're done.
      Now you can open the database with DB Browser.