• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help to save and retrieve the values form SharedPreferences in android

hello,



I am trying to make an application which will save five location in the form of Longitude and Latitude and when I will reach near any of the locations application should give a alert.
I wish to use SharedPreferences for this can anyone please guide me how to save and retrieve the values form SharedPreferences in android


Regards,
Javed.
 
In the "source" activity do this:

SharedPreferences settings = context.getSharedPreferences(
"yourfilename.bla", Context.MODE_PRIVATE);

SharedPreferences.Editor editor = settings.edit();

editor.putString("key", value);
editor.commit();


In the target activity do this:

SharedPreferences preferences = getSharedPreferences(
"yourfilename.bla", Context.MODE_PRIVATE);

String value= preferences.getString("key", "");


The second parameter in getString is the default value you want returned if "key" isn't found.
 
Back
Top Bottom