How to access shared preference between activities in android?
I have two activities A and B . Activity A has a form and by clicking on submit button it saves the form data into shared preference. Activity B has to retrieve data from the shared preferences saved by activity A . I went through so many forums and got suggestion to uses getSharedPreference(Filename,Mode)
instead of getPreference(Mode)
. But still it does not work. Is there any other method to do this job instead of creating a class in activity A specially to extract shared preference values for public use.
Please suggest a perfect solution for this. I even used the mode as WORLD_READABLE.
I think the problem is that the editor is not actually committing changes due to how you are opening your SharedPreferences
.
SharedPreferences.Editor editor = getSharedPreferences("udata",MODE_WORLD_READABLE).edit();
Change MODE_WORLD_READABLE
to Context.MODE_PRIVATE
and see if that helps.
You can try using PreferenceManager.getDefaultSharedPreferences
. The JavaDoc is here: http://developer.android.com/reference/android/preference/PreferenceManager.html
Your other attempts should work, but without seeing the code I'm not sure why it is isn't.
There was some initialization problem. Now I got the solution. Thanks for all your support
链接地址: http://www.djcxy.com/p/9158.html上一篇: 未对齐数据的运行速度