I'm using the PreferenceActivity and want to restore its state while the device rotation.
I want to save the state onSaveInstanceState method:
@Override
protected void onSaveInstanceState(Bundle icicle) {
super.onSaveInstanceState(icicle);
icicle.putString("LevelsValue", levelPref.getSummary().toString());
}
And in the onCreate method :
if (savedInstanceState!=null)
Toast.makeText(getApplicationContext(), "savedInstanceState is not null", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), "savedInstanceState is null", Toast.LENGTH_SHORT).show();
And I'm always getting the savedInstanceState is null
message.
I know that I can use the onStop
and onResume
methods, but I think that is not the right approach.
我通过使用的onResume和onStop方法解决了这个问题
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.