如果我使用 SharedPreferences,使用 onSaveInstanceState 是否有用

Is it usefull to use onSaveInstantState if I use SharedPreferences

我有一个关于表演的问题。如果我使用 SharedPreferences,使用 onSaveInstantState 有用吗?

我的意思是,如果值得做一个条件来测试:

if(savedInstanceState != null) {
    // load with on save instant state
}

else {
    // load with shared preferences
}

或者我应该始终从 SharedPreferences 加载数据?

谢谢

是的,它仍然有用,有很多东西不能保存在 SharedPrefrences 字典中,例如列表、地图或任何其他自定义对象。

您应该计划保存有关 SharedPrefrences if you want the data to be persisted through application uses (after your application has been destroyed), and save information onSaveInstanceState bundle if you want to persist data through configuration changes 的信息(旋转、字体大小更改、语言更改)。

如果您需要数据在任何情况下都保持不变,请选择 SQLite