将数据库嵌入到分布式应用程序的 .apk 中 [Android]
我的问题是我认为很简单,但我认为答案不会...... 我的应用程序中有相当多的内容要使其正常运行,我正在考虑将所有内容放入数据库中,并将其分发到嵌入式数据库中,并将应用程序放在市场。 唯一的麻烦是我不知道该怎么做。 我知道我可以从 Eclipse DDMS 中提取包含数据库内容的文件 .db,并且我想我需要将其放入应用程序的资产文件夹中,但是如何让应用程序使用它来重新生成应用程序数据库? 如果您有任何代码或帮助的链接,那就太好了。 谢谢
My question is I think quite simple but I don't think the answer will be...
I have quite a lot of content to have in my application to make it run properly, and I'm thinking of putting all of it in a database, and distribute it in an embeded database with the application in the market.
The only trouble is that I have no idea of how to do that.
I know that I can extract a file .db from Eclipse DDMS with the content of my database, and I suppose I need to put it in the asset folder of my application, but then how to make the application use it to regenerate the application database?
If you have any link to some code or help, that would be great.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了实现您的要求,您可以将 .db 文件放在 asset/ 目录中,并在第一次启动应用程序时将其复制到位......
其中“initialiseDatabase”是一些标志,指示应用程序是否具有首次推出。
尽管如此,如果您正在考虑存储大量数据,正如您所提到的:我强烈建议您避免使用它来使 APK 文件膨胀,并在应用程序安装后使用互联网连接(从托管服务器)下载数据库记录。推出。通过这种方式,您可以显示一个进度条,向用户指示为什么他们需要等待很长时间才能开始使用该应用程序。让 APK 特别大通常会首先阻止人们安装它。
Well to achieve what you're asking, you could put the .db file in your assets/ directory and copy it into place the first time you start your app.....
Where "initialiseDatabase" is some flag indicating if the app has been launched for the first time.
Although, if you are looking at storing a lot of data, as you mentioned: I strongly recommend you avoid bloating the APK file with it, and use the Internet connection to download the database records (from a hosted server) after the app has been launched. This way you can show a progress bar indicating to the user why they are waiting a long time to start using the app. Making the APK especially large usually deters people from installing it in the first place.
您可以实现中间的解决方案:使用上面的方法,但不是分发数据库文件,而是将其放在服务器上的某个位置。根据我的经验,获取文件只占处理时间的 10%,剩下的就是解析图像并将其序列化到数据库
You can implement middle-of-the-road solution: Use approach above, but instead of distributing db file put it on server somewhere. In my experience getting files is only 10% of processing time, rest of it is parsing and serializing images to db