Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

android - 附带数据库的应用程序(Ship an application with a database)

If your application requires a database and it comes with built in data, what is the best way to ship that application?

(如果您的应用程序需要一个数据库,并且它带有内置数据,那么最好的运输方法是什么?)

Should I:

(我是不是该:)

  1. Precreate the SQLite database and include it in the .apk ?

    (预先创建SQLite数据库并将其包含在.apk ?)

  2. Include the SQL commands with the application and have it create the database and insert the data on first use?

    (在应用程序中包括SQL命令,并让它创建数据库并在首次使用时插入数据吗?)

The drawbacks I see are:

(我看到的缺点是:)

  1. Possible SQLite version mismatches might cause problems and I currently don't know where the database should go and how to access it.

    (可能的SQLite版本不匹配可能会导致问题,并且我目前不知道数据库应该去哪里以及如何访问它。)

  2. It may take a really long time to create and populate the database on the device.

    (在设备上创建和填充数据库可能会花费很长时间。)

Any suggestions?

(有什么建议么?)

Pointers to the documentation regarding any issues would be greatly appreciated.

(有关任何问题的文档指针将不胜感激。)

  ask by Heikki Toivonen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just found a way to do this in ReignDesign blog in an article titled Using your own SQLite database in Android applications .

(我刚刚在ReignDesign blog中找到了一种在Android应用程序中使用自己的SQLite数据库的文章。)

Basically you precreate your database, put it in your assets directory in your apk, and on first use copy to /data/data/YOUR_PACKAGE/databases/ directory.

(基本上你预先创建数据库,将它放在apk的assets目录中,并首先使用copy到/data/data/YOUR_PACKAGE/databases/目录。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...