java - Android saving preferences privately to my app but accessible from all classes -
i want save preference can access classes within app. should not accessible outside app, since contain user login data.
in android documentation understanding mode_private should it. if utilize mode_private can access preference within class created it.
class1.java:
.... sharedpreferences prefs = getpreferences(mode_private); sharedpreferences.editor editprefs = prefs.edit(); editprefs.putstring("mypref", "myvalue"); editprefs.commit(); ... class2.java:
... sharedpreferences prefs = getpreferences(mode_private); string mystring = prefs.getstring("mypref", " "); ... if phone call getstring within same class created it, returns myvalue (even after closing app, , without putting again).
if phone call getstring in class within same app, returns " ".
thanks!
try this:
preferencemanager.getdefaultsharedpreferences(getapplicationcontext()); for documentation see: http://developer.android.com/reference/android/preference/preferencemanager.html#getdefaultsharedpreferences(android.content.context)
java android sharedpreferences saving-data
No comments:
Post a Comment