almost 6 years ago
Android provides some features to store and retrieve data of an application. SharedPreferences is one of the simple and easy way among them.We save data in key, value pair.
We have to call getSharedPreferences(), It returns the SharedPrefrence instance thats point the file containing the value.
SharedPreferences userPreferences=context.getSharedPreferences(EMPLOYEES_INF, Context.MODE_PRIVATE);
There are other modes also:
*MODE_APPEND: It appends new preferences to already existed preferences.
*MODE_PRIVATE: Its the default mode,It means the file accessed by only the calling application.
*MODE_WORLD_READABLE: allow all applications to have read access to the file.
*MODE_WORLD_WRITEABLE: allow all applications to have write access to the file.
We save any value by using SharedPrefrences.Editor class. We have to call the edit() method of Editor class.
Editor editor = userPreferences.edit();
We can get these value like this :
SharedPreferences userPreferences = this.getSharedPreferences(SharedPreferenceManager.EMPLOYEES_INF, 0);
String value1 =userPreferences.getString("key1", "");
String value2 = userPreferences.getString("key1", "");
Methods available in Editor class:
* remove(String key): It removes the value according to the passed key.
* clear(): It remove all values from the specific editor.
* putLong(String key, long value): It saves a long value.
* putInt(String key, int value): It saves an integer value.
* putFloat(String key, float value): It saves a float value.
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Terms of Service
| © copyright 2021 FindNerd.com. All rights reserved.
Sign up using