CopyPastor

Detecting plagiarism made easy.

Score: -1; Reported for: Open both answers

Possible Plagiarism

Plagiarized on 2018-02-24
by Rushabh Shah

Original Post

Original - Posted on 2015-08-10
by Jorgesys



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I am explaining you a simple sharedpreference example , hope this help.
>> **For saving value in sharedpreference :**
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit(); editor.putString("name", "XYZ"); editor.putInt("idName", 1); editor.apply();
>> **Retrieve data from preference :**
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); String restoredText = prefs.getString("text", null); if (restoredText != null) { String name = prefs.getString("name", "No name defined");//"No name defined" is the default value. int idName = prefs.getInt("idName", 0); //0 is the default value. }
Comment if you have doubt.
***Happy Coding...***
###Setting values in Preference:
// MY_PREFS_NAME - a static String variable like: //public static final String MY_PREFS_NAME = "MyPrefsFile"; SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit(); editor.putString("name", "Elena"); editor.putInt("idName", 12); editor.commit();
###Retrieve data from preference:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); String restoredText = prefs.getString("text", null); if (restoredText != null) { String name = prefs.getString("name", "No name defined");//"No name defined" is the default value. int idName = prefs.getInt("idName", 0); //0 is the default value. }
more info:
[**Using Shared Preferences**][1]
[**Shared Preferences**][2]

[1]: http://developer.android.com/guide/topics/data/data-storage.html#pref [2]: http://developer.android.com/reference/android/content/SharedPreferences.html

        
Present in both answers; Present only in the new answer; Present only in the old answer;