Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I store data of the few applications in one place?

Tags:

android

sqlite

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?

like image 683
SorryForMyEnglish Avatar asked Feb 04 '15 19:02

SorryForMyEnglish


People also ask

What are the various ways of storing the data of apps?

Internal storage, external storage, shared preferences, database, and shared storage are some of the storage options offered by Android.

Where does the application data be stored?

Every application in the device has some private storage in the internal memory and you can find this in android/data/your_package_name directory. Apart from this internal storage, the rest of the storage is called the Shared Storage i.e. every application with the storage permission can access this part of the memory.

What type of data you should not store in the database?

Finally, you shouldn't store credit card information in your database unless you absolutely need to. This includes credit card owner names, numbers, CVV numbers, and expiration dates.


3 Answers

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

like image 80
Bhuvan Avatar answered Oct 02 '22 22:10

Bhuvan


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.

like image 40
Tal Kanel Avatar answered Oct 02 '22 21:10

Tal Kanel


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.

like image 21
Muzikant Avatar answered Oct 02 '22 22:10

Muzikant