IT. Expert System.

Android Reference

SharedPreferences


android.content

Interface SharedPreferences



  • public interface SharedPreferences
    Interface for accessing and modifying preference data returned by Context.getSharedPreferences(java.lang.String, int). For any particular set of preferences, there is a single instance of this class that all clients share. Modifications to the preferences must go through an SharedPreferences.Editor object to ensure the preference values remain in a consistent state and control when they are committed to storage. Objects that are returned from the various get methods must be treated as immutable by the application.

    Note: currently this class does not support use across multiple processes. This will be added later.

    Developer Guides

    For more information about using SharedPreferences, read the Data Storage developer guide.

    See Also:
    Context.getSharedPreferences(java.lang.String, int)
    • Method Detail

      • getAll

        Map<String,?> getAll()
        Retrieve all values from the preferences.

        Note that you must not modify the collection returned by this method, or alter any of its contents. The consistency of your stored data is not guaranteed if you do.

        Returns:
        Returns a map containing a list of pairs key/value representing the preferences.
        Throws:
        NullPointerException
      • getString

        String getString(String key,
                       String defValue)
        Retrieve a String value from the preferences.
        Parameters:
        key - The name of the preference to retrieve.
        defValue - Value to return if this preference does not exist.
        Returns:
        Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not a String.
        Throws:
        ClassCastException
      • getStringSet

        Set<String> getStringSet(String key,
                               Set<String> defValues)
        Retrieve a set of String values from the preferences.

        Note that you must not modify the set instance returned by this call. The consistency of the stored data is not guaranteed if you do, nor is your ability to modify the instance at all.

        Parameters:
        key - The name of the preference to retrieve.
        defValues - Values to return if this preference does not exist.
        Returns:
        Returns the preference values if they exist, or defValues. Throws ClassCastException if there is a preference with this name that is not a Set.
        Throws:
        ClassCastException
      • getInt

        int getInt(String key,
                 int defValue)
        Retrieve an int value from the preferences.
        Parameters:
        key - The name of the preference to retrieve.
        defValue - Value to return if this preference does not exist.
        Returns:
        Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not an int.
        Throws:
        ClassCastException
      • getLong

        long getLong(String key,
                   long defValue)
        Retrieve a long value from the preferences.
        Parameters:
        key - The name of the preference to retrieve.
        defValue - Value to return if this preference does not exist.
        Returns:
        Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not a long.
        Throws:
        ClassCastException
      • getFloat

        float getFloat(String key,
                     float defValue)
        Retrieve a float value from the preferences.
        Parameters:
        key - The name of the preference to retrieve.
        defValue - Value to return if this preference does not exist.
        Returns:
        Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not a float.
        Throws:
        ClassCastException
      • getBoolean

        boolean getBoolean(String key,
                         boolean defValue)
        Retrieve a boolean value from the preferences.
        Parameters:
        key - The name of the preference to retrieve.
        defValue - Value to return if this preference does not exist.
        Returns:
        Returns the preference value if it exists, or defValue. Throws ClassCastException if there is a preference with this name that is not a boolean.
        Throws:
        ClassCastException
      • contains

        boolean contains(String key)
        Checks whether the preferences contains a preference.
        Parameters:
        key - The name of the preference to check.
        Returns:
        Returns true if the preference exists in the preferences, otherwise false.
      • edit

        SharedPreferences.Editor edit()
        Create a new Editor for these preferences, through which you can make modifications to the data in the preferences and atomically commit those changes back to the SharedPreferences object.

        Note that you must call SharedPreferences.Editor.commit() to have any changes you perform in the Editor actually show up in the SharedPreferences.

        Returns:
        Returns a new instance of the SharedPreferences.Editor interface, allowing you to modify the values in this SharedPreferences object.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 219 / 158732504. Delta: 0.03227 с