"activity.onCreate()"是否正常?多次调用的方法 [英] Is it normal for the "activity.onCreate()" method to be called multiple times
本文介绍了"activity.onCreate()"是否正常?多次调用的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Activity的onCreate方法中有一些代码,并注意到它被调用了3次.这是正常行为吗?谢谢.
I have some code in the onCreate method an Activity and noticed that it is being called three times. Is it normal behaviour? Thanks.
推荐答案
您可能需要通读 OnCreate一次.但是,在许多情况下,可能会导致您的活动被杀死并重获新生.因此,onCreate将再次被调用.
OnCreate will only be called one time for each lifetime of the Activity. However, there are a number of situations that can cause your activity to be killed and brought back to life. Thus, onCreate will be called again.
要正确地支持此功能,可以将状态信息保存在onSaveInstanceState中,并从创建时获得的状态捆绑包中还原状态信息.
To support this properly, you can save state information in onSaveInstanceState and restore it fron the state bundle you get in on create.
这篇关于"activity.onCreate()"是否正常?多次调用的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文