Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple Android SharedPreferences Implementation: Method Failure - All Values Are Null
    primarykey
    data
    text
    <p>I'm attempting to null check several values in my source code and it appears they are all returning null. I should be able to use these value in my new class due to my SharedPreferences implementation but it appears it is not working. (I appear to be overlooking something simple.)</p> <p>Startpoint Class SharedPreferences Implementation:</p> <pre><code>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(); </code></pre> <p>Endpoint Class SharedPreferences Implementation:</p> <pre><code>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(); </code></pre> <p>The values in my endpoint are showing as null when I check them - any idea why? I believe they should n't be null due to my implementation of SharedPreferences but they are all still returning null. (I could have sworn I implemented this correctly - I have no idea why I cannot retrieve these values - I believe everything should be functioning - but strangely: it is not.) </p> <p>First Attempt At Solution Provided:</p> <pre><code>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(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload