149 Android SharedPreferences Tutorial Part 1 |

slidenerd · 111K views · 2013 · 6:25

Open on YouTube

Software (other)Web developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when beginners need to persist small pieces of data, such as login state, first-launch flags or button selections, and want a quick walkthrough of SharedPreferences.

Recommended by 5 people across 5 different months, 2014 to 2017.

What it is

A short 2013 tutorial from the slidenerd channel on Android's SharedPreferences API. It explains how to store simple key-value pairs of primitive types, how they are saved as an XML file in the app's data folder, and how to use getPreferences or getSharedPreferences with an Editor to write and commit values.

What people said

Recommends Shakeeb Ayaz · 2014-02 · Stack Overflow · on “Android- How to skip first activity”

save a Boolean flag on first launch in sharedpreference [LINK] and read this value before activity launch now check boolean value so your code will be something like this @Override protected void onCreate(Bundle savedInstanceState) { .... Boolean flag; loadSavedPreferences(); Intent myIntent; if(flag){ myIntent = new Intent(CurrentActivity.this, FirstActivity.class); savePreferences() }else{ myIntent = new Intent(CurrentActivity.this, NextActivity.class); private void loadSavedPreferences() { SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(this); flag = sharedPreferences.getBoolean("FirstLaunch", true); } private void savePreferences() { SharedPreferences

Recommends prabhakaran · 2014-06 · Stack Overflow · on “How To Get Value From another Activity?”

There are many way to pass value from one activity to another activity like shared preference, bundle,intent putextra, database.. for a beginner you can use the shared preference.. i hope this will help you.. 1.Following tutorial may help you: Basic Tutorial for shared preference(Login and register form) [this video] Simple example for shared preference with source code [LINK]

Recommends Trev · 2015-07 · Stack Overflow · on “Android Java: Get Open WiFi-Networks”

Do you mean that you just want to store the strings for the SSID and keys so that you can easily restore and connect later? The easiest way is to use SharedPreferences to store any data. Here is a a tutorial by slidenerd that is very easy to follow. [this video] I'm a noob too, so whenever I have questions, I head straight to slidenerd or thenewboston on youtube and then start digging through tech documentation once I have a basic understanding.

Recommends mik dass · 2016-04 · Stack Overflow · on “Android : Save Button Instance”

You can use the SharedPreferences class to save the user selection.This video can help you get started - [this video] .Just save the user selection of button in a key value pair with sharedpreferences class.On activity restart or relaunch just check for the value in the shared preferences instance and accordingly set the button setClickable(true) or setClickable(false). EDIT: clickButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //same code as above without the setClickable() on buttons //remove the button.setClickable(false); for rest of the buttons editor.putString("session", "akash").commit(); editor.commit(); startActivity(show); //Start the activ

Recommends Abhriya Roy · 2017-01 · Stack Overflow · on “How to transfer the data of a variable from one Activity to another”

You can use Shared Preferences to store the data in the former activity, and then later retrieve it in the child activity. Using Shared Prefences, you can store the value of editText like this SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit(); editor.putString("name", "Elena"); editor.putInt("idName", 12); editor.commit(); Now, in the other activity, you can retrieve it as 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(