The easiest way to pass data between application in Android

放肆的年华 提交于 2019-12-25 02:22:02

问题


What's the easiest way to pass data(string value) between two android applications with less or even without permissions? Also in my case first application sends data to un-existed application which is installing and it can't listen for intent right now.

Thanks.


回答1:


Your question is tricky when you can't ensure that both applications are running. In cases like that, you must rely on some form of persistent storage.

If you're concerned with only a small amount of data, Android provides a SharedPreferences class to share preferences between applications. Most notably, you can add a OnSharedPreferenceChangeListener to each application so they can be notified when the other changes the value.

You can find more information on various different forms of persistent storage on the Android website (http://developer.android.com/guide/topics/data/data-storage.html).




回答2:


So as you are mentioning intent and extras put to it is the way to go.

If you want to let an application receive data even if it's still installing there is no straight-forward way.

One way is as follows: In the receiver-part of your code, send a received successfully-extra to the sender-application. If the sender-application does not get the received successfully-message after some time, store the data and wait until the application is installed. you may store this data on sd-card and let the other application read that on first use.

you can also do a check if the application is installed with PackageManager.



来源:https://stackoverflow.com/questions/8842569/the-easiest-way-to-pass-data-between-application-in-android

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