3

What is the best way to pass simple data such as a String between applications? The String is some field that is known in the sender app and is needed by the receiver app.

I looked into storing it in a MODE_WORLD_READABLE SharedPreferences, but I won't necessarily know the package name (this would exist in a library), the value can be set by various apps, so it'd be difficult to look up.

I was thinking have both apps contain BroadcastReceivers. When the receiver app is opened, it sends a custom Intent for the sender app to receive to tell it that it's ready to receive. Upon seeing that Intent, the sender app then sends another Intent with my string value to the receiver app to get.

nicobatu
  • 1,377
  • 3
  • 15
  • 34
  • Are the applications always going to be on the same device? – Aaron McIver Jul 05 '12 at 22:08
  • Yes, I was looking at device storage as well but I feel like it should be simpler than that. – nicobatu Jul 05 '12 at 22:09
  • 3
    "What is the best way to pass simple data such as a String between applications?" -- that is impossible to answer in the abstract without knowing more of your scenario. "When the receiver app is opened, it sends an Intent to the sender app to tell it that it's ready to receive" -- will you know an action string or something to use? That feels like it is the same problem as "I won't necessarily known the package name". You might wish to add a few more paragraphs to your question elaborating on the bigger picture. – CommonsWare Jul 05 '12 at 22:12
  • Added some clarification, yes I was thinking of sending my own custom Intents that both apps would know about. – nicobatu Jul 05 '12 at 22:17
  • Check out the documentation on Content Providers as well as this stack overflow post on sharing data between applications. – 74U n3U7r1no Jul 11 '15 at 04:35

1 Answers1

1

@CommonsWare What you're saying is incorrect. You can share data, for example a string between two applications. Please take a look here: Data sharing between two applications and also: http://developer.android.com/training/sharing/send.html

"I was thinking have both apps contain BroadcastReceivers." This is not needed. Google provides a very simple and easy solution and example.

Community
  • 1
  • 1
Noman Arain
  • 1,172
  • 4
  • 19
  • 45
  • Please note that you should post the useful points of an answer here, on this site, or your post risks being deleted as ["Not an Answer"](http://meta.stackexchange.com/q/8259). You may still include the link if you wish, but only as a 'reference'. The answer should stand on its own without needing the link. – Andrew Barber Nov 02 '12 at 20:03
  • Yes, I didn't update this answer but I ended up using ContentProviders. Thanks! – nicobatu Nov 03 '12 at 00:16