问题
I create only a table from code but inside still empty. I instead insert data by pull a file out and insert by SQLite Browser when run the emulator then, put it back to the data/data/package_name/file.db with this solution, after run the program I can see the list of information in Emulator. But moving the application on a real device, I cannot see any list of information on a real device. How should I do?
Because my application just provide the data to user, so user has no need to add or edit data to the database. In addition the data don't need to change very often. that's why I use SQLite Browser to insert data.
I know that there are some security constrain in (not-rooted) device. However, are there any suggestion about the solution.. How should I edit my code?
回答1:
You can package your database in your res/assets/ folder and then copy it onto the /data/data/YOUR_APP_FOLDER/databases if the database does not exist (i.e., first install) or if it's older than the file in the assets folder (i.e., updated apk).
This post has a full working example: http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
来源:https://stackoverflow.com/questions/6168806/the-data-disappear-after-moving-the-application-on-a-real-device-in-android