I have troubles reading my SharedPreference from ContactView.Java in my MainActivity.Java
This is what i have in my ContactView.Java:
SharedPreferences settings = getSharedPreferences("SelectedContact", MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("contactName", name);
editor.putString("contactPhone", phoneNo);
editor.commit();
and this in my OnCreate for setting them to the TextViews:
SharedPreferences settings = getSharedPreferences("SelectedContact", MODE_PRIVATE);
String name = settings.getString("contactName", "");
//the second parameter set a default data if “contactName” is empty
if (!name.isEmpty()){
textView1.setText(name);
}
String phoneNo = settings.getString("contactPhone", "");//the second parameter set a default data if “contactName” is empty
if (!phoneNo.isEmpty()){
textView2.setText(phoneNo);
}
Now when i go to MainActivity i would like to read them:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String phoneNo = sharedPreferences.getString("contactPhone", "");
String name = sharedPreferences.getString("contactName", "");
But the Strings seem to be empty and not contain any name or phoneNo what am i doing wrong?