Created
May 7, 2018 06:29
-
-
Save ashutoshpw/0cd6c1aeaf26b3f0d8485c57ffd92e40 to your computer and use it in GitHub Desktop.
Android Shared Preference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity | |
SharedPreferences sharedpreference; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); | |
SharedPreferences.Editor editor = settings.edit(); | |
editor.putString("key","value"); | |
editor.commit(); | |
// For Async Commit | |
//editor.apply(); | |
// Read | |
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); | |
String key = settings.getString("key", "DEFAULT_VALUE"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment