开发者

Android PreferenceManager without visual component?

I am trying to get a SharedPreferences object from the PreferenceManager but don't want t开发者_如何学Goo pass in the Context to the class.

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

SharedPreferences pref = 
   PreferenceManager.getDefaultSharedPreferences(Some Global Context);


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜