How do I get the SharedPreferences from a PreferenceActivity in Android?

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-04-10T19:51:04Z Indexed on 2010/04/10 19:53 UTC
Read the original article Hit count: 560

Hi,

I am using a PreferenceActivity to show some settings for my application. I am inflating the settings via a xml file so that my onCreate (and complete class methods) looks like this:

public class FooActivity extends PreferenceActivity {

 @Override
 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  addPreferencesFromResource(R.xml.preference);
 }

}

The javadoc of PreferenceActivity states, that

These preferences will automatically save to SharedPreferences as the user interacts with them. To retrieve an instance of SharedPreferences that the preference hierarchy in this activity will use, call getDefaultSharedPreferences(android.content.Context) with a context in the same package as this activity.

But how I get the name of the SharedPreference in another Activity? I can only call

getSharedPreferences(name, mode)

in the other activity but I need the name of the SharedPreference which was used by the PreferenceActivity. What is the name or how can i retrieve it?

© Stack Overflow or respective owner

Related posts about android

Related posts about preferences