[英]Is it a good pratice to restore savedInstanceState?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
return;
}
// processing
}
Is it a good practice to avoid processing further if the savedInstanceState
is not null? 如果
savedInstanceState
不为null, savedInstanceState
避免进一步处理? does this have any drawback? 这有什么缺点吗?
I expect this code is not what you want as there can be different times you want to have savedInstanceState so if it is set pull out the data you will have saved so the user has the same state though they may have rotated their phone. 我希望这段代码不是您想要的代码,因为可能有不同的时间要拥有saveInstanceState,因此,如果设置了该代码,则会拉出将要保存的数据,因此用户可能具有相同的状态,尽管他们可能已经旋转了手机。
You may want to look at this question and answers 您可能想看看这个问题和答案
What's onCreate(Bundle savedInstanceState) 什么是onCreate(捆绑的saveInstanceState)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.