Totti
Totti

Reputation: 675

sharedpreferences doesn't save data

i want to save data in the first activity and use it in the second activity, on the first activity i used this:

android.content.SharedPreferences someData;
public static String filename = "mySharedString";
someData = getSharedPreferences(filename, 0);
android.content.SharedPreferences.Editor editor = someData.edit();
editor.putString("HostIP", "192.168.1.101");

in the second activity i used this

android.content.SharedPreferences someData;
TextView Message;
public static String filename = "mySharedString";
String HostIP;
someData = getSharedPreferences(filename, 0);
HostIP = someData.getString("HostIP", "0");
phoneNumber.setText(HostIP);

but the results prints on phonenumber is 0 not 192.168.1.101

Upvotes: 0

Views: 573

Answers (1)

Samir Mangroliya
Samir Mangroliya

Reputation: 40416

After editing data in sharedPrefrence, commit() it.

editor.commit();

Upvotes: 4

Related Questions