简体   繁体   English

还原savedInstanceState是否是一个好习惯?

[英]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.

相关问题 savedinstancestate一个数组列表,将其还原到recyclerview - savedinstancestate an arraylist an restore it to recyclerview 如何恢复fragmentInstanceState的片段? - How to restore savedInstanceState of fragment? 如何从savedInstanceState恢复ViewPager - How to Restore ViewPager from savedInstanceState Android Native Redux是一个很好的实践吗? - Is Android Native Redux a good pratice? 我应该在onCreate还是onRestoreInstanceState中恢复savedinstancestate? - Should I restore savedinstancestate in onCreate or in onRestoreInstanceState? 恢复w / o savedInstanceState后如何恢复片段状态? - How to restore fragment state after resume w/o savedInstanceState? 扩展对象类并直接管理事件是一个好习惯吗? - Extend Object Class and manage directly the events is a good pratice? 在onCreate中检查savedInstanceState是否为null是判断设备是否已旋转的好方法? - Is checking savedInstanceState for null in onCreate a good way to tell if the device was rotated? onCreate(savedInstanceState)savedInstanceState为NULL - onCreate(savedInstanceState) savedInstanceState is NULL SavedInstanceState为null - SavedInstanceState is null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM