Reputation: 987
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.
Upvotes: 0
Views: 553
Reputation: 301
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.
Upvotes: 2