Using Sharedpreferences To Share Data Between Two Separate Android Applications
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.
Post a Comment for "Using Sharedpreferences To Share Data Between Two Separate Android Applications"