4

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?

Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
  • 2
    Not really an answer but you could have one App and use in-app purchase for the upgrade. – DrC Dec 27 '12 at 03:47
  • I learned that it's ok for a free app to use the in-app purchase system to unlock the "pro" version. This isn't my preferred solution since it bypasses some user protections, such as being able to get an automatic refund. But, it's the path of least resistance, so I'm going with it. – Peri Hartman Dec 30 '12 at 04:01
  • The user may (and should) be annoyed if they uninstall both pro and lite versions and data is left behind. So I wonder whether there is some way for the 3rd, silent, app to get uninstall when pro & lite are uninstalled. – Tom Apr 28 '13 at 23:28

2 Answers2

3

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

mem
  • 111
  • 2
  • 8
  • If I'm following you, you're saying in short: copy the database. Maybe the same thing can be accomplished by changing file ownership? I'm not yet at the point to produce the pro app, so this idea will sit for a while. I'll try to remember to post back here in the future with my results. – Peri Hartman Jun 06 '13 at 14:07
  • Not sure about changing the file ownership, but copying the db or reading/writing the data from lite to pro will work. – mem Jun 07 '13 at 00:28
1

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

Aha
  • 134
  • 8
  • 1
    This assumes that the database is has no content generated on the device by the user. – Chris Stratton Dec 27 '12 at 03:58
  • 1
    yes, but if there is generated data, its not the perfect answer.. but also can consider upload these content to the server as well (periodically ) – Aha Dec 27 '12 at 04:02
  • I'm not following you, or maybe you are missing one of my points. First, my database is not "in" the app - it's owned and created by the app. It's a sqlite db. So, are you suggesting writing a service that owns the database? What do you mean by "pull the db from your server..."? – Peri Hartman Dec 27 '12 at 04:04
  • i thought you have a ready database that your app need to use ( for example dictionary apps database are ready in advance), in this case you can download the database from a web address, for example to put it drobpox with a share link, and garp the database by the link). but since its generated by the app than you need another solution, like to find a way to store your database in SD card rather than the internal memory , look at this [one] (http://stackoverflow.com/questions/4433208/android-use-sqlite-database-on-sd-card-not-using-internal-android-data-store-a) – Aha Dec 27 '12 at 04:16
  • Yes, I could put it on the SD card. I'm trying to avoid that since it makes the db so vulnerable. – Peri Hartman Dec 27 '12 at 18:22
  • You can also write to the online database. Having the database online is also very useful in case the user's local database gets wiped for any reason - eg, user error, hardware error, software error, lost phone, etc. – ban-geoengineering Dec 29 '14 at 14:47