I am developing an Android app. I am testing using onSaveInstanceState event in activity. But it is not working as I expected, because value string is always empty when I retrieve it back onCreate event.
This is my activity
@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
outState.putString("message","Hello world!");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(savedInstanceState!=null)
{
Toast.makeText(getBaseContext(),savedInstanceState.getString("message"),Toast.LENGTH_SHORT).show();
//Log.i("DATA_FROM_STATE",savedInstanceState.getString("message"));
}
}
When I run activity and change orientation, it is always toasting empty message. When I test uncommenting the Log line, it is giving me error because data string is empty or null. Why it is not working? How can I save and retrieve correctly?