Code example for SharedPreferences

Methods: containsgetIntgetString

0
        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. 
     * @param c - The Activity's Context