导出一个Android应用程序时,包括数据库数据 [英] Include database data when exporting an Android application

查看:108
本文介绍了导出一个Android应用程序时,包括数据库数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我出口我的应用程序的.apk文件,签名然后再进行安装。但是,当我跑我的应用程序,它会显示一个错误,因为有一个在我的数据库中没有数据。

I export my application to .apk file, sign it and then install it. But when I run my app, it displays an error because there's no data in my database.

该数据库是,当我安装的应用程序创建一个新的,所以所有的数据都将丢失!

The database was created as a new one when I installed the application, so all the data were lost!

导出一个Android应用程序时我怎样才能包括数据库中的数据?

How can I include database data when exporting an Android application?

推荐答案

选项#1:打包数据库作为原始资源或资产,并使用流的数据库复制到它应有的位置,当应用程序第一次运行

Option #1: Package the database as a raw resource or asset, and use streams to copy that database to its proper position when the app is first run.

选项2:包装SQL语句填充数据库作为原始资源,并在执行这些语句的 SQLiteOpenHelper 的onCreate() 方法。

Option #2: Package SQL statements to populate the database as a raw resource, and execute those statements in your SQLiteOpenHelper's onCreate() method.

选项#3:把智慧直在Java code来填充你的数据库中的 SQLiteOpenHelper 的onCreate()方法。

Option #3: Put the smarts straight in your Java code to populate your database in your SQLiteOpenHelper's onCreate() method.

第4个选项:下载第一次运行的数据库,并将其复制到它应有的位置。

Option #4: Download the database on first run and copy it to its proper position.

等等。

这篇关于导出一个Android应用程序时,包括数据库数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆