Skip to content Skip to sidebar Skip to footer

Using Sharedpreferences To Share Data Between Two Separate Android Applications

There will be two separate applications running on an Android device at the same time. We're responsible for App1. Here's what will be happening on the Android device: App1 will

Solution 1:

even if shared preferences could be shared between process (see @CommonsWare answer..) then it sounds like the most poor design solution for the problem you describes. in fact, it smells like horrible idea, and I'm sure eventually it won't work anyway!

saying SharedPreferences is solution to communication between to different apps/ process in android, is like completely ignore all android API, and core components!

SharedPreferences not designed to be some kind of message queue between process. not even close to that!

android provides much more elegant solutions for communicating between different apps, and sharing data between them

for example:

  • remote Service binding (app1 starts service which app2 can bind to)
  • sending broadcast from one app to another when some event accures and rceive it from the other app with BroadcastReceiver
  • app1 can implement and expose ContentProvider which can be accessed from app2

and there's more!

I suggest you better understand android's core components (Service , BroadcastReceiver, Activity, ContentProvider) before you get any decision how to implement your apps. I can't imagine a way to create good functional application without using at least 3 of the above. you can varify that with reading the first page written in Android developers getting started guide - http://developer.android.com/guide/components/fundamentals.html

links:

http://developer.android.com/reference/android/app/Service.htmlhttp://developer.android.com/reference/android/content/BroadcastReceiver.htmlhttp://developer.android.com/reference/android/content/ContentProvider.htmlhttp://developer.android.com/guide/components/bound-services.html

Solution 2:

The group responsible for App2 wants to use SharedPreferences to accomplish all this

That is not a very good idea. Quoting the documentation for SharedPreferences:

Note: currently this class does not support use across multiple processes. This will be added later.

Solution 3:

As Tal said it is POOR to use Shared preference to communicate in two process, the IPC (inter process communicate, Binder in Android) with Service is a better solution to fulfill full control between two Android process. Here is a example about how to use IPC in Music player and it's client.

Post a Comment for "Using Sharedpreferences To Share Data Between Two Separate Android Applications"