host database with do-nothing app so lite and pro can access

拟墨画扇 提交于 2019-12-06 05:26:31

问题


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?


回答1:


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).




回答2:


why dont you have the database in your server and whenever the app installed ( regardless the lite or the pro version) just pull the database from your server ( and overwrite the exist one if its exist ) , this is good also for your database security, becuase i can simply browse the apk file with zip softwar and get your database. the other benefit is that the apk file will be smaller in its size, more important it will it will solve your problem



来源:https://stackoverflow.com/questions/14049095/host-database-with-do-nothing-app-so-lite-and-pro-can-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!