Last active
August 23, 2020 06:24
-
-
Save shibbirweb/21959006ef0eb60462d4454bd7ffd563 to your computer and use it in GitHub Desktop.
Android Shared Preferences Helper Class
This file contains hidden or 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 ActivityOrFragment extends AppCompatActivity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| // usage | |
| // save in shared preference | |
| SharedPreferencesHelper.init(getApplicationContext(), "Shared Preference Name") | |
| .setEditor() | |
| .putString("key", "value") | |
| .apply(); | |
| // retrieve from shared preference | |
| String stringValue = SharedPreferencesHelper.init(getApplicationContext(), "Shared Preference Name") | |
| .get() | |
| .getString("key", null); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment