如何运输Android应用程序与数据库?应用程序、数据库、Android

2023-09-11 10:17:01 作者:来日方长

如果你的应用需要一个数据库,并配有内置的数据,究竟是把该应用程序的最佳方法是什么?

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

1)precreate SQLite数据库,其中包括它在APK?

1) Precreate the sqlite database and include it in the apk?

2)包括与该应用程序的SQL命令,并让它创建数据库和插入数据在第一次使用?

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

缺点我看

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

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

2)可能需要很长的时间,在设备上创建和填充数据库。

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

您的想法?有关的任何问题指向的文件将是巨大的。

Your thoughts? Pointers to documentation regarding any issues would be great.

推荐答案

我刚刚找到一个办法做到这一点的ReignDesign博客在一篇题为的使用您自己的SQLite数据库在Android应用程序的。基本上你precreate数据库,把它放在你的资产目录中的APK,并在第一次使用拷贝到/数据/数据​​/ YOUR_PACKAGE /数据库/目录下。

I just found a way to do this in ReignDesign blog in an article titled Using your own SQLite database in Android applications. 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.