The data disappear after moving the application on a real device in android

删除回忆录丶 提交于 2019-12-12 18:07:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!