Code example for SharedPreferences

Methods: containsgetIntgetString

        SharedPreferences p = c.getSharedPreferences(PREFERENCES_FILE, MODE_WORLD_READABLE);
         * Get the position and value of the spinner from the file, or a default value if the 
         * key-value pair does not exist. 
        this.mPos = p.getInt(POSITION_KEY, SpinnerActivity.DEFAULT_POSITION);
        this.mSelection = p.getString(SELECTION_KEY, "");
         * SharedPreferences doesn't fail if the code tries to get a non-existent key. The 
         * most straightforward way to indicate success is to return the results of a test that 
         * SharedPreferences contained the position key. 
          return (p.contains(POSITION_KEY));
     * Write the application's current state to a properties repository. 
Contextual code suggestions in your IDE  Get Codota for Java