5

I have several applications built on the same engine. This engine is storing data in SQLite. The database structure is the same for all applications. I need to organize a common storage for all these applications.

For example, there is an application A and B. First user installed the application A and added data, then installed the application B and this is necessary to synchronize databases of those two apps. Using a function of Content Providers will not work because in this case application B will not work without the application A. And also we will not know which application user installs first.

There is an idea to synchronize the database of all applications and each application will remain with its own database, but then I will have a copy of the databases. Means as many apps are installed as many copies of databases I will have.

Perhaps there is some kind of a neat way to realize the idea?

SorryForMyEnglish
  • 1,181
  • 7
  • 14
  • Can you explain at a little higher level what you're trying to accomplish? I'm wondering why the user is going to install multiple similar apps. And is it going to be common for them to do that? – bryan Feb 06 '15 at 21:57
  • So, my first APP is https://play.google.com/store/apps/details?id=com.aosc My second app is https://play.google.com/store/apps/details?id=com.numbersforsms Both app have a chat with history. So, I need have the same conversation history on the booth app when they installed on the same device. – SorryForMyEnglish Feb 06 '15 at 22:13
  • See: http://stackoverflow.com/questions/7053809/share-sqlite-database-between-2-android-apps – John Feb 13 '15 at 19:47

3 Answers3

4

Why don't you try using "sharedUserId" across all your apps. With this you can access the data of the other apps as well.

Assuming you already know all the your others apps, on first load of every application you start searching for a common folder where you create your database. This folder can be in your sdcard. If you find the DB file there then you can open it and use it. Otherwise you create one. Then use the same database across all apps?

I'm not sure what are the implications of opening/writing to the same DB from various apps. Maybe you need to figure out a way for locking mechanism during writes (Maybe create a .lock file when writing to the DB?)

Community
  • 1
  • 1
Bhuvan
  • 285
  • 1
  • 3
  • 11
2

I encountered myself same design problem (multiple apps using same engine contains persistent SQLite database tables, Services, and tons of logic).

after I did my own research, I afraid that the conclusion was that the only way doing that is: doing that in Googles's way:

Google Play Services is a process that google made up exactly to solve this problem for their own scenario - engine that should be always available to all apps (including thier own). that's mean that it's an independent application that exposes it services and content providers to all apps.

Google force Google Play Services installation seamlessly in background via Google Play store app. that's a privilege that no other app can have, because they controlling both apps, and the OS Android itself (not fair!)

so, if you can force your users to download dedicated application only for your engine (like Google do) - that's great!

if not - then you will have to settle until then with a Master/primary app that must be installed, and it's the only one the exposing the data and services to all other.

Tal Kanel
  • 10,475
  • 10
  • 60
  • 98
  • You are talking about the Google play service. Yes, this is a correct idea, but here is a problem - only Google is allowed to force people to install additional apps. If I will go this way 90% users will refuse to install additional app. PS. Amazon does not have Google play service on its devices and does not allow to publish apps which will not work without it. – SorryForMyEnglish Feb 13 '15 at 09:29
  • Yes. But still, you can tell your users that in order to use one of your apps - they have to redirect to download page of your engine. Of course lots of users would refuse, but that's still an option.. – Tal Kanel Feb 13 '15 at 09:33
1

You can store the database on the external storage and access it from all of your applications (Use getExternalStorageDirectory).

Use the openOrCreateDatabase method of the SQLiteDatabase class to access it and read/write data from it.

Since accessing from multiple processes can cause locks, I suggest you manage that yourself using a file with the name/packagename of the locking application so you can sync the data access between your applications.

Muzikant
  • 8,070
  • 5
  • 54
  • 88