I am trying to get the SharedPreferenes that I have saved in two different activities into my SMS activity. They are both saved as Strings.
For the phone number, it is saved as a string and is just directly inside of the onActivityResult (because it is getting the phone number out of the contact list)
prefs = getSharedPreferences(prefName, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
//---save the values in the EditText view to preferences---
editor.putString("phoneNumber", phn_no);
//---saves the values---
editor.commit();
phoneN.setText(phn_no);
Toast.makeText(getBaseContext(), "Saved",
Toast.LENGTH_SHORT).show();
For the message, it has a method.
public void AddMessage() {
btnSave.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
prefs = getSharedPreferences(prefName, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
//---save the values in the EditText view to preferences---
//editor.putInt("id", Integer.parseInt(e_id.getText().toString()));
editor.putString("message", editMessage.getText().toString());
//---saves the values---
editor.commit();
Toast.makeText(getBaseContext(), "Saved",
Toast.LENGTH_SHORT).show();
}
}
);
}
I have tried doing this:
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
String phoneNum = settings.getString("phoneNumber", "");
String message = settings.getString("message", "");
Log.d(TAG, message.toString());
Log.d(TAG, phoneNum.toString());
But it is not saved in this. Might have did it wrong...
Thanks in advance for your help!
EDIT
also tried to do this:
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(this);
if (spref.contains("message")) {
String mes = spref.getString("message", "");
Log.d(TAG, mes)
; }
if(spref.contains("phoneNumber")){
String phn = spref.getString("phoneN", "");
Log.d(TAG,phn);
}
it did not work. Nothing has showed up in the Log.