[英]Why is onRestoreInstanceState called for a view when the activity is destroyed?
[英]Will onRestoreInstanceState() still be called when activity is recreated?
快速提問:在某些情況下,需要破壞一項活動以釋放資源。 在這種情況下,當用戶導航回到上述活動時,將首先調用onCreate()。 我問如果發生這種情況,是否仍會調用onRestoreInstanceState()。
當從先前保存的狀態重新初始化活動時,在onStart()
之后onStart()
onRestoreInstanceState()
方法,在此處以savedInstanceState
給出
是的,它會的。
首先使用保存的實例狀態作為捆綁包調用onCreate()
。 然后onStart()
。 然后,使用傳遞給onCreate()
的同一包來調用onRestoreInstanceState()
onCreate()
。
這使您能夠恢復狀態無論是在選項onCreate()
或onRestoreInstanceState()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.