Storing data in SharedPreferences accessible to all activities

Yes. SharePreferences do exactly this. In every activity you can this:

SharedPreferences prefs = getSharedPreferences(ApplicationConstants.PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(name, value);
editor.commit();

And then retrieve values in other activty doing this:

mPrefs.getString(name, "");

This is the documentation: http://developer.android.com/reference/android/content/SharedPreferences.html

And this is a good example to start with:

http://myandroidsolutions.blogspot.it/2012/03/android-preferenceactivity.html


Yes, that's the whole purpose of it.

Here's how you should write to it, via Editor

    final SharedPreferences shp         = ctx.getSharedPreferences(ctx.getString(R.string.app_name), Context.MODE_PRIVATE);
    final SharedPreferences.Editor ed   = shp.edit(); 
    ed.putString("var1", "var1");
    ed.putString("var2", "var2");

And to load it:

shp.getString("var1", "defvalue");

I have a better version. As sometimes when you try to do getSharedPreferences you might get an error as it could not be found. This is how I store values in my Android projects.

Add

SharedPreferences sharedPreferences=this.getSharedPreferences("packagename", Context.MODE_PRIVATE);

 sharedPreferences.edit().putString("username", "specify name here").apply();

Package Name can be directly copied from top of the activity ex: com.example.name.projectname

Retrieve

String username = sharedPreferences.getString("username","");