How to edit shared preferences in an activity other than the one it is created in?

微笑、不失礼 提交于 2019-12-25 03:34:49

问题


I have created some shared preference in an activity and I want to modify it in a broadcast reciever...How can I do that??? Please help...

I have tried looking but couldn't get the answer


回答1:


You should be able to do:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor edit = prefs.edit();

using the context passed into the BroadcastReceiver.



来源:https://stackoverflow.com/questions/7853564/how-to-edit-shared-preferences-in-an-activity-other-than-the-one-it-is-created-i

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