You can use the SharedPreferences API to store key-value pairs, provide simple access methods, and control the access permissions of the SharedPreferences file. The following describes how to use the SharedPreferences API. Obtain a SharedPreferences object. Use the following method to obtain or create a SharedPreferences file object getSharedPreferences ()-Use this if you need multiple shared preference files identified by name, which you specify with the first parameter. you can call this from anyContext in your app. getPreferences ()-Use this from an Activity if you need to use only one shared preference file for the activity. because this retrieves a default shared Preference file that belongs to the activity, you don't need to supply a name. for example, the following code is executed in a Fragment to obtain. string. the SharedPreferences file of the preference_file_key resource flag is opened in private mode, indicating that the file can only be accessed in your own app [java] Context context = getActivity (); SharedPreferences sharedPref = context. getSharedPreferences (getString (R. string. preference_file_key), Context. MODE_PRIVATE); when naming a SharedPreference file, it is best to use a unique name within the app range, such as com. ex Ample. myapp. PREFERENCE_FILE_KEY In addition, getPreferences () can get a SharedPreference file that only belongs to the current activity [java] SharedPreferences sharedPref = getActivity (). getPreferences (Context. MODE_PRIVATE); if it is enabled with MODE_WORLD_READABLE or MODE_WORLD_WRITEABLE, other apps can also access the data to be written to the Shared Preferences file. First, create a SharedPreferences through edit. the Editor object is put into data through putInt (), putString (), and commit () is called to save the changes. For example, [java] SharedPreferences sharedPref = GetActivity (). getPreferences (Context. MODE_PRIVATE); SharedPreferences. editor editor = sharedPref. edit (); editor. putInt (getString (R. string. saved_high_score), newHighScore); editor. commit (); to read data from the Shared Preferences file, you can call methods such as getInt () and getString (), for example: [java] SharedPreferences sharedPref = getActivity (). getPreferences (Context. MODE_PRIVATE); long defaultVal = getResources (). getInteger (R. string. s Aved_high_score_default); long highScore = sharedPref. getInt (getString (R. string. saved_high_score), defaultVal); the second parameter indicates the default value when the provided key does not exist.