Note that there are some explanatory texts on larger screens.

plurals
  1. POPre-populated databases in Android: Trying to put the pieces together
    text
    copied!<p>I have been gathering information in this site and others about the best way to include a pre-populated sqlite database in Android. I just would like to confirm that I understood the reasons of why something that should be trivial… it is not.</p> <p>So could someone please tell me if my following conclusions are correct or wrong?:</p> <ul> <li>the main reason many people suggest copying a pre-populated database file from the assets folder to "/data/data/YOUR_PACKAGE/databases/" is because there is <strong>no way</strong> to access a database file in the assets folder or doing that would be overly complex (?). (Could someone clarify which of these two answers is the right one ?)</li> <li>another important reason database files in the assets folder must be copied somewhere else is because files in that location cannot be updated. Then even if a database in the assets folder could be open, this would be useful only if such database does not have to be modified. <strong>UPDATE:</strong> <em>I launched a new thread focussing only on this issue:</em> <a href="https://stackoverflow.com/questions/8914673/opening-a-read-only-database-directly-in-the-assets-folder">Opening a read only database directly in the assets folder</a>.</li> <li>files in the assets folder can be only 1 Mb size (unless they have certain file extensions such as mp3). Note that this restriction is not relevant if: your database is smaller that 1 Mb, or you do not mind dividing your database in 1 Mb chunks and putting them together at runtime, or you do not mind distributing a database file with a mp3 extension.</li> <li>If the database file is copied from the assets folder to "/data/data/YOUR_PACKAGE/databases/", there is no way to delete the original database file at the assets folder to avoid having a duplicated file. This is also because files in the assets folder cannot be modified.</li> </ul> <p>Making the puzzle a bit more complex: I found in the comments to the accepted answer of this question: <a href="https://stackoverflow.com/questions/513084/how-to-ship-an-android-application-with-a-database">Ship an application with a database</a> that copying the database from the assets folder to another location in fact does not work on some devices running 2.3+. Is that accurate ? If that is true, then the best alternative would be to download the database file from the web at first run ?</p> <p>Thanks for any clarification.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload