I have a simple edittext on first activity and user enter some text and moves to second activity and from there to third and so on. Now when the user comes back to first activity the edit text should show him the text he enetered in the edittext.
SampleText= (EditText) findViewById(R.id.smpltxt);
SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Saving the value :
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putString("MyString", SampleText);
}
Restoring the value :
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
String myString = savedInstanceState.getString("MyString");
}
I'm unable to get the text when he comes back to the first activity.
Can anyone say me what and where am I going wrong ?
Replace
with
also check whether
SampleText.getText()==null
if so no need to add it.