Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access shared preference between activities in android? [closed]

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.

like image 812
Surjya Narayana Padhi Avatar asked Sep 17 '11 15:09

Surjya Narayana Padhi


1 Answers

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.

like image 146
Jon Willis Avatar answered Nov 17 '22 11:11

Jon Willis