static void main? Is not exits in Android, but OnCreate
Em 08/11/2012 07:55, "Jayawant Jagtap" <[email protected]> escreveu:
> Hello,
>
> I want to get instance of the SharedPreferences in the class which is not
> derived from Activity or Service, Can I get it without paasing Context
> object to that class.
>
> class Helper{
> private SharedPreferences mPref = *null* ;
> private String data="";
>
> private *static* *final* String *KEY* = "key";
>
> public static void init(Context a){
> mPref= a.getSharedPreferences(*PREF_FILE*, 0);
>
> data=mPref.getString(*KEY*, *""*);
> }
>
> public string getdata{
> return data; //In this method if data is empty string
> due to init method is not called in some case,I want to call init() method
> from here.
> } //But I don't have context object. I
> can't call init before each getdata() call because there also context
> object is not available in some cases.
> } // I can store Context object as Helper
> class variable,but it is failing if first getdata() call executes before
> init() call.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en