string - Simple Android SharedPreferences Implementation: Method Failure - All Values Are Null -


i'm attempting null check several values in source code , appears returning null. should able use these value in new class due sharedpreferences implementation appears not working. (i appear overlooking simple.)

startpoint class sharedpreferences implementation:

sharedpreferences prefs=getpreferences(context.mode_private);     sharedpreferences.editor editor=prefs.edit();     editor.putboolean("name",true);     editor.putboolean("cap",true);     editor.putboolean("code",true);     editor.putboolean("time",true);     editor.putboolean("ssid",true);     editor.commit(); 

endpoint class sharedpreferences implementation:

sharedpreferences prefs=getpreferences(context.mode_private);     sharedpreferences.editor editor=prefs.edit();    if (new == null) {         log.d(tag, "broken value! debug! debug!");      prefs.getboolean("new", true);     prefs.getboolean("user", true);     prefs.getboolean("name", true);     prefs.getboolean("data", true);     prefs.getboolean("login", true);     editor.commit(); 

the values in endpoint showing null when check them - idea why? believe should n't null due implementation of sharedpreferences still returning null. (i have sworn implemented correctly - have no idea why cannot retrieve these values - believe should functioning - strangely: not.)

first attempt @ solution provided:

sharedpreferences prefs=getpreferences(ndef_pref, context.mode_private);         sharedpreferences.editor editor=prefs.edit();             prefs.getboolean("name", true);             prefs.getboolean("cap", true);             prefs.getboolean("code", true);             prefs.getboolean("time", true);             prefs.getboolean("ssid", true);             editor.commit(); 

you not getting sharedpreferences, try instead:

sharedpreferences prefs = getsharedpreferences(prefs_name, context.mode_private); 

where prefs_nameis name give file.

also can't this:

sharedpreferences.editor editor=prefs.edit(); prefs.getboolean("new", true); 

since editor class doesn't have method... instead should use prefs variable values.

and take @ saving , restoring... value in both cases "name", others false.

edit

example:

string ndef_pref = "prefs"; sharedpreferences prefs = getsharedpreferences(ndef_pref, context.mode_private); prefs.getboolean("name", true); prefs.getboolean("cap", true); prefs.getboolean("code", true); prefs.getboolean("time", true); prefs.getboolean("ssid", true); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -