提供与 .APK 文件打包在一起的数据库还是将其单独托管在网站上?

发布于 2024-08-09 02:28:40 字数 655 浏览 3 评论 0原文

以下是关于我的应用程序的一些背景信息:

我正在开发一个 Android 应用程序,它将向用户显示随机的引用或诗句。为此,我使用 SQLite 数据库。 DB 的大小大约为 5K 到 10K 条记录,在以后的版本中,随着新引文和诗句的添加,可能会增加到 1M。因此,当应用程序或数据库的新版本发布时,用户需要更新数据库。

在浏览了一些在线论坛后,我似乎有两种可行的方式可以提供数据库: 1. 将其与应用程序的 .APK 文件捆绑在一起,或者 2.将其上传到我的应用程序的网站,用户必须从该网站下载它

我想知道哪种方法更好(如果除这些方法之外还有其他方法,请告诉我)。

经过一段时间的思考这个问题,我对上述方法有以下一些想法:

方法一: 用户将随应用程序一起获取数据库,而无需单独下载。安装因此会更容易。但是,每次有新版本的数据库时,用户都必须重新安装应用程序。另外,如果数据库很大,安装起来也会很麻烦。

方法2: 用户必须从网站下载完整的数据库(尽管我可以通过方法 1 提供数据库的小型示例版本)。但是,安装程序将更简单且尺寸更小。此外,我将能够轻松地为那些可能不想要更新版本的应用程序的人提供数据库的未来版本。

您能否从技术和管理的角度告诉我哪种方法更好,为什么?

如果有第三种或第四种方法比这两种方法更好,请告诉我。

谢谢你!

安卓

Here is some background about my app:

I am developing an Android app that will display a random quote or verse to the user. For this I am using an SQLite database. The size of the DB would be approximately 5K to 10K records, possibly increasing to upto 1M in later versions as new quotes and verses are added. Thus the user would need to update the DB as and when newer versions are of the app or DB are released.

After reading through some forums online, there seem to be two feasible ways I could provide the DB:
1. Bundle it along with the .APK file of the app, or
2. Upload it to my app's website from where users will have to download it

I want to know which method would be better (if there is yet another approach other than these, please do let me know).

After pondering this problem for some time, I have these thoughts regarding the above approaches:

Approach 1:
Users will obtain the DB along with the app, and won't have to download it separately. Installation would thereby be easier. But, users will have to reinstall the app every time there is a new version of the DB. Also, if the DB is large, it will make the installable too cumbersome.

Approach 2:
Users will have to download the full DB from the website (although I can provide a small, sample version of the DB via Approach 1). But, the installer will be simpler and smaller in size. Also, I would be able to provide future versions of the DB easily for those who might not want newer versions of the app.

Could you please tell me from a technical and an administrative standpoint which approach would be the better one and why?

If there is a third or fourth approach better than either of these, please let me know.

Thank you!

Andruid

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘过的浮云 2024-08-16 02:28:40

我为 Android 构建了一个类似的应用程序,它会定期更新政府机构的数据。使用 perl 或类似工具在设备上构建 Android 兼容数据库相当容易,然后从网站将其下载到手机;这效果相当好,而且用户每次下载应用程序时都会获取当前数据。如果您想避免使用主数据存储空间,也应该可以将数据扔到 SD 卡上,这对于我的应用程序来说是一个更大的问题,因为它有大约 6Mb 的数据库。

为了让 Android 对数据库感到满意,我相信你必须执行以下操作(我使用 perl 构建我的数据库)。

$st = $db->prepare( "CREATE TABLE \"android_metadata\" (\"locale\" TEXT DEFAULT 'en_US')");
$st->execute();

$st = $db->prepare( "INSERT INTO \"android_metadata\" VALUES ('en_US')");
$st->execute();

我有一个更新活动,用于检查天气更新是否可用,如果是,则显示“立即更新”屏幕。下载过程如下所示,位于 DatabaseHelperClass 中。

public void downloadUpdate(final Handler handler, final UpdateActivity updateActivity) {
    URL url;
    try {
        close();

        File f = new File(getDatabasePath());
        if (f.exists()) {
            f.delete();
        }

        getReadableDatabase();
        close();

        url = new URL("http://yourserver.com/" + currentDbVersion + ".sqlite");

        URLConnection urlconn = url.openConnection();
        final int contentLength = urlconn.getContentLength();
        Log.i(TAG, String.format("Download size %d", contentLength));
        handler.post(new Runnable() {
            public void run() {
                updateActivity.setProgressMax(contentLength);
            }
        });

        InputStream is = urlconn.getInputStream();

        // Open the empty db as the output stream
        OutputStream os = new FileOutputStream(f);

        // transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024 * 1000];
        int written = 0;
        int length = 0;
        while (written < contentLength) {
            length = is.read(buffer);
            os.write(buffer, 0, length);
            written += length;
            final int currentprogress = written;
            handler.post(new Runnable() {
                public void run() {
                    Log.i(TAG, String.format("progress %d", currentprogress));
                    updateActivity.setCurrentProgress(currentprogress);
                }
            });
        }

        // Close the streams
        os.flush();
        os.close();
        is.close();

        Log.i(TAG, "Download complete");

        openDatabase();
    } catch (Exception e) {
        Log.e(TAG, "bad things", e);
    }
    handler.post(new Runnable() {
        public void run() {
            updateActivity.refreshState(true);
        }
    });
}

另请注意,我在数据库文件的文件名中保留了版本号,并在服务器上的文本文件中保留了指向当前版本号的指针。

I built a similar app for Android which gets periodic updates with data from a government agency. It's fairly easy to build an Android compatible db off the device using perl or similar and download it to the phone from a website; and this works rather well, plus the user gets current data whenever they download the app. It's also supposed to be possible to throw the data onto the sdcard if you want to avoid using primary data storage space, which is a bigger concern for my app which has a ~6Mb database.

In order to make Android happy with the DB, I believe you have to do the following (I build my DB using perl).

$st = $db->prepare( "CREATE TABLE \"android_metadata\" (\"locale\" TEXT DEFAULT 'en_US')");
$st->execute();

$st = $db->prepare( "INSERT INTO \"android_metadata\" VALUES ('en_US')");
$st->execute();

I have an update activity which checks weather updates are available and if so presents an "update now" screen. The download process looks like this and lives in a DatabaseHelperClass.

public void downloadUpdate(final Handler handler, final UpdateActivity updateActivity) {
    URL url;
    try {
        close();

        File f = new File(getDatabasePath());
        if (f.exists()) {
            f.delete();
        }

        getReadableDatabase();
        close();

        url = new URL("http://yourserver.com/" + currentDbVersion + ".sqlite");

        URLConnection urlconn = url.openConnection();
        final int contentLength = urlconn.getContentLength();
        Log.i(TAG, String.format("Download size %d", contentLength));
        handler.post(new Runnable() {
            public void run() {
                updateActivity.setProgressMax(contentLength);
            }
        });

        InputStream is = urlconn.getInputStream();

        // Open the empty db as the output stream
        OutputStream os = new FileOutputStream(f);

        // transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024 * 1000];
        int written = 0;
        int length = 0;
        while (written < contentLength) {
            length = is.read(buffer);
            os.write(buffer, 0, length);
            written += length;
            final int currentprogress = written;
            handler.post(new Runnable() {
                public void run() {
                    Log.i(TAG, String.format("progress %d", currentprogress));
                    updateActivity.setCurrentProgress(currentprogress);
                }
            });
        }

        // Close the streams
        os.flush();
        os.close();
        is.close();

        Log.i(TAG, "Download complete");

        openDatabase();
    } catch (Exception e) {
        Log.e(TAG, "bad things", e);
    }
    handler.post(new Runnable() {
        public void run() {
            updateActivity.refreshState(true);
        }
    });
}

Also note that I keep a version number in the filename of the db files, and a pointer to the current one in a text file on the server.

雄赳赳气昂昂 2024-08-16 02:28:40

如果您打算将数据库存储在您的网站上,那么我建议您只对您的网络服务器进行 rpc 调用并以这种方式获取数据,因此设备永远不必处理本地数据库。使用缓存管理器来避免多次查找也会有所帮助,这样页面就不必在每次重新加载页面时查找数据。此外,如果您需要更新数据,则不必每次都发送新的应用程序。使用 HttpClient 非常简单,如果您需要任何示例,请告诉我

If you are going to store the db on your website then I would recommend that you just make rpc calls to your webserver and get data that way, so the device will never have to deal with a local database. Using a cache manager to avoid multiple lookups will help as well so pages will not have to lookup data each time a page reloads. Also if you need to update the data you do not have to send out a new app every time. Using HttpClient is pretty straight forward, if you need any examples please let me know

熟人话多 2024-08-16 02:28:40

听起来你的应用程序和数据库是紧密绑定的——也就是说,如果没有数据库,数据库就毫无用处,而如果没有应用程序,数据库也毫无用处,所以我想说,继续将它们放在同一个 .apk 中。

话虽这么说,如果您预计数据库随着时间的推移变化非常缓慢,但应用程序变化得更快,并且您不希望用户必须在每个新应用程序修订版中下载数据库,那么您可能需要将它们解绑。要实现此功能,您可以执行以下两种操作之一:

  1. 将它们安装为单独的应用程序,但确保它们使用 sharedUserId 标记。
  2. 将它们安装为单独的应用程序,并为数据库。这样其他应用程序也可以使用您的数据库(如果有用的话)。

It sounds like your app and your db are tightly bound -- that is, the db is useless without the database and the database is useless without the app, so I'd say go ahead and put them both in the same .apk.

That being said, if you expect the db to change very slowly over time, but the app to change quicker, and you don't want your users to have to download the db with each new app revision, then you might want to unbundle them. To make this work, you can do one of two things:

  1. Install them as separate applications, but make sure they share the same userID using the sharedUserId tag in the AndroidManifest.xml file.
  2. Install them as separate applications, and create a ContentProvider for the database. This way other apps could make use of your database as well (if that is useful).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文