主机数据库,什么都不做的应用程序,以便精简版和PRO可以访问 [英] host database with do-nothing app so lite and pro can access

查看:147
本文介绍了主机数据库,什么都不做的应用程序,以便精简版和PRO可以访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

和许多人一样,我将有一个精简版和亲的版本我的应用程序。他们使用一个数据库,这将是在内部存储。我想一个用户能够买到的亲版本,然后安装,而不会丢失数据库。

部分解决: 我已经看到了如何使多个应用其他职位使用同一个数据库。本质上,这需要两件事:

  
      
  1. 在两个清单声明相同的机器人:sharedUserId在清单中,
  2.   
  3. 在一个应用程序必须使用其他应用程序的情况下打开数据库。
  4.   

我试过这个,是的,它的作品!

的问题:卸载精简版的版本删除分贝。按照这样的:用户安装精简版的版本。精简版的版本创建数据库和他愉快地创建并保存数据在里面。后来,他决定安装亲。 Pro版本访问的精简版创建的数据库和一切工作正常。最后,他unstalls的精简版,因为他不需要它了。现在,亲将停止工作,因为该数据库是由Android的删除时,精简版的版本卸载。

什么解决方案?一个解决方案,想到的是有三分之一的应用程序,拥有数据库。这是一家简单的被安装什么都不做的应用程序,并具有相同的名称作为包。那就没有UI并且实际上永远不会被运行。然后,精简版和专业应用软件,可以安装或卸载对数据库没有影响。

这是一个好主意?有没有更好的办法(比创建一个供应商数据库等)?如果这是一个合理的做法,我该如何创建一个没有用户界面,是不是服务的应用程序?

解决方案

这听起来像你决定去与在应用程序内购买的亲的应用程序,然而这可能也是一个可行的解决方案。

从您的文章,你有一个精简版的应用程序,包含数据库。当用户购买亲的应用程序,你有亲的应用程序访问的精简版数据库进行读/写。如果这些假设是真的,为什么不能做到以下几点:

  1. 在亲的应用程序启动时,有它创建一个数据库,所以亲们的应用程序现在拥有自己的数据库。

  2. 在创建该数据库

    后,请检查是否是精简版的应用程序数据库存在,我假设你已经这样做了,因为你是在你的职业的应用程序打开的精简版应用程序数据库。

  3. 如果是精简版的应用程序数据库存在,写从精简版的应用程序数据库中的数据为亲的应用程序数据库。现在,在你的职业分贝,你将拥有所有的精简版数据库的数据。当使用亲的应用程序,该应用程序应该调用自己的数据库前进,而不是精简版分贝。现在,从精简版的应用程序中的数据被传输到亲,用户可以卸载精简版应用程序,而不必担心数据会丢失。

  4. 如果是精简版数据库不存在,则什么也不会发生和亲应用程序加载与它自己的数据库,空白数据(或任何你可能需要preloaded)。

Like many others, I will have a "lite" and a "pro" version of my app. They use a database, which will be in the internal storage. I would like a user to be able to buy the pro version and install it without losing the database.

Partial Solution: I've seen other posts on how to have multiple apps use the same database. Essentially, this requires two things:

  1. both manifests declare the same android:sharedUserId in the manifest,
  2. one of the apps must open the database using the other app's context.

I tried this and, yes, it works!

The Problem: Uninstalling the lite version deletes the db. Follow this: the user installs the lite version. The lite version creates the database and he happily creates and saves data in it. Later he decides to install the pro. The pro version accesses the db created by the lite and everything works fine. Finally, he unstalls the lite because he doesn't need it any more. Now, the pro will stop working because the db was deleted by Android when the lite version was uninstalled.

What Solution? One solution that comes to mind is to have a third app that owns the database. It is a "do nothing" app which simple gets installed and has the same name as the package. It would have no UI and in fact never be run. Then, the lite and pro apps could be installed or uninstalled with no effect on the db.

Is this a good idea? Is there a better way (other than creating a provider for the db)? If this is a reasonable approach, how do I create an app with no UI that isn't a service?

解决方案

It sounds like you decided to go with the in-app purchase of the pro app, however this may have also been a viable solution.

From your post you have a lite app that contains the database. When the user purchases the pro app, you have the pro app accessing the lite database for read/write. If these assumptions are true, why not do the following:

  1. When the pro app starts, have it create a database, so the pro app now has its own database.

  2. After that database is created, check to see if the lite app database exists, I assume you are already doing this because you are opening the lite app db in your pro app.

  3. If the lite app db exists, write the data from the lite app db into the pro app db. Now in your pro db you will have all lite db data. While using the pro app, the app should make calls to its own database going forward, and not the lite db. Now that the data from the lite app is transferred to the pro, the user can uninstall the lite app without worry that the data will be lost.

  4. If the lite db does not exists, then nothing happens and the pro app loads with its own database, blank data(or whatever you may need preloaded).

这篇关于主机数据库,什么都不做的应用程序,以便精简版和PRO可以访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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