I have a question :
So i have this line of code(i got it from tuts in thenewboston) :
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
My question is : what did we do in this line? i think we create an object from SharedPreferences, but what about the PreferenceManager Class?is it the super Class of SharedPreference?is it has some relation with OOP?
Thanks all ~
PS : English is not my native languange, so sorry if i made some mistake’s 😀
The PreferenceManager has a static method named getDefaultSharedPreferences. What this means is that you can call the method without first constructing an instance of ‘PreferenceManager’. Static methods do not operate on instance variables within a class.
Static methods can create instances of objects, and return them. In this case, the static method created a new SharedPreferences object that you’re storing in a local variable.
Think of it like this: A static method exists once for all the instances of an object. Every time you call that static method, it’s doing the same thing regardless of what each object might know. Based on the context passed into it, it will create a SharedPreferences object that you can use.
I hope this helps!