问题
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.
回答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.
来源:https://stackoverflow.com/questions/11353195/passing-string-data-between-android-applications