Passing String data between Android applications

不想你离开。 提交于 2019-12-04 04:02:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!