views:

118

answers:

1

I am trying to get a SharedPreferences object from the PreferenceManager but don't want to pass in the Context to the class.

Can I get a "global" context from inside my class?

SharedPreferences pref = 
   PreferenceManager.getDefaultSharedPreferences(Some Global Context);
+1  A: 

You should generally have a reference to a context from any major component of your application (Activity, Service, etc...) If this is a utility class then passing a reference of a context should suffice.

Is there a particular pattern you are trying to implement.. or avoid implementing?

Quintin Robinson