How to access shared preferences between actions in android?

I have two actions A and B. Activity A has a form and, by clicking the submit button, saves the form data in general preferences. Activity B should extract data from the general settings stored by activity A. I went through so many forums and got an offer to use getSharedPreference(Filename,Mode) instead of getPreference(Mode) . But it still won’t work. Is there any other method for accomplishing this task, and not for creating a class in activity A specifically for retrieving publicly available preference values.

Please suggest the perfect solution for this. I even used this mode as WORLD_READABLE.

+7
source share
3 answers

I think the problem is that the editor doesn’t actually make any changes due to the way you open your SharedPreferences .

  SharedPreferences.Editor editor = getSharedPreferences("udata",MODE_WORLD_READABLE).edit(); 

Change MODE_WORLD_READABLE to Context.MODE_PRIVATE and see if that helps.

+3
source

You can try using PreferenceManager.getDefaultSharedPreferences . 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 this is not so.

0
source

There was some initialization problem. Now I got a solution. Thanks for your support.

0
source

All Articles