简体   繁体   中英

onSaveInstanceState in Activity vs Custom View

It seems that onSaveInstanceState when overridden in a custom View is not called if the activity that created the View also has onSaveInstanceState overridden. Why is this and is there a way to call both? Is one better to use than the other? Since not all Views are custom I find that it might be necessary to have the activity call onSavedInstanceState too.

In addition if you call it in the Custom View, how do you tell the activity to not perform the time consuming tasks, upon rotation, that were used to create the View in onCreate in the first place? The onSaveInstanceState in the View was used to stop the activity from performing time consuming tasks again and again.

You have to add super.onSaveInstanceState() in your overridden method, it calls this method in all attached fragments and views.

It is a good practice to call super.onSaveInstanceState() every time you override it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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