Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing and persisting data between multiple Android applications

I'm developing a group of complex Android applications that need to share common state and configuration settings.

For example, see this picture explaining my scenario:

enter image description here

I want that APP 1, APP 2 and APP 3 be able to access (read/write) data to the common storage area. Additionally, I need uninstall protection i.e. I don't want the data to be removed when the user uninstalls any of the apps.

I've already read about SQLite databases, ContentProviders and writing on Internal and External storage, but each of the above mentioned methods have disadvantages as listed below:

  • SQLite database: DB is deleted on app uninstall and is private to each app
  • ContentProvider: The data is removed when the app with the ContentProvider is removed
  • Internal storage: Is private to each app and data is deleted on app uninstall (http://developer.android.com/training/basics/data-storage/files.html#InternalVsExternalStorage)
  • External storage: Is unreliable (user may remove SD card)
  • Store on server: Not possible, user may not have reliable internet connection

EDIT:

I don't want any dependencies on Google Play Services because I will be distributing the apps via Play Store and as 3rd party downloads.

Please help me out.

like image 723
jazdev Avatar asked Sep 12 '14 16:09

jazdev


2 Answers

Google Drive sort of does this for you. You basically get granted permission to a local filesystem that is backed by a remote one. On most phones this is getting preinstalled so the uninstall issue you are worried about is less of an issue.

You could create a folder for your apps that you can then read/write.

https://developers.google.com/drive/android/

like image 113
Greg Giacovelli Avatar answered Nov 10 '22 04:11

Greg Giacovelli


You can use the shared preferences object to read and write preferences data from a file. Most important is to use MODE_MULTI_PROCESS. The bit MODE_MULTI_PROCESS is used if multiple processes are mutating the same SharedPreferences file.

Use the following code:

SharedPreferences shPrefernces = context.getSharedPreferences("filename", MODE_MULTI_PROCESS);
String s1 = shPrefernces.getString("keytosearch1", "");
String pass = shPrefernces.getString("keytosearch2", "");
like image 23
Nipun Anand Avatar answered Nov 10 '22 02:11

Nipun Anand