简体   繁体   English

重新创建活动时仍会调用onRestoreInstanceState()吗?

[英]Will onRestoreInstanceState() still be called when activity is recreated?

Quick question: In some cases, an activity will need to be destroyed to free up resources. 快速提问:在某些情况下,需要破坏一项活动以释放资源。 In that scenario, when the user navigates back to said activity, onCreate() will first be called. 在这种情况下,当用户导航回到上述活动时,将首先调用onCreate()。 I'm asking if onRestoreInstanceState() will still be called if ever that happens. 我问如果发生这种情况,是否仍会调用onRestoreInstanceState()。

当从先前保存的状态重新初始化活动时,在onStart()之后onStart() onRestoreInstanceState()方法,在此处以savedInstanceState给出

Yes, it will. 是的,它会的。

First onCreate() is called with the saved instance state as a bundle. 首先使用保存的实例状态作为捆绑包调用onCreate() Then onStart() is called. 然后onStart() Then onRestoreInstanceState() is called with the same bundle that was passed to onCreate() . 然后,使用传递给onCreate()的同一包来调用onRestoreInstanceState() onCreate()

This gives you the option to restore the state either in onCreate() or in onRestoreInstanceState() . 这使您能够恢复状态无论是在选项onCreate()onRestoreInstanceState()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM