简体   繁体   中英

Usage of onSaveInstanceState and setRetainInstance in Fragments

I would like to understand the usage and also the difference between the methods onSaveInstanceState() and setRetainInstance() in Android Fragments .

Thanks a lot on advance.

onSaveInstanceState() is used when you need to save state so you can restore it if Android kills your process to save memory.

setRetainInstance() is used for fragments that you don't want to re-create on device rotation, etc. If you don't call it, Android will serialize their state in a Bundle, and re-create them along with the parent activity.

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