Summary
Let's conclude this chapter by quickly enumerating what you have learned about handling configuration changes:
- Activities get destroyed and re-created during configuration changes.
- Avoid putting lots of data and logic into activities so configuration changes occur quickly.
- Let Android provide the appropriate resources.
- Use singletons to hold data outside of activities to make it easier to destroy and re-create activities during configuration changes.
- Take advantage of the default
onSaveInstanceState()
callback to save UI state on views withandroid:id
s. - If a fragment can survive with no issues across an activity destroy and create cycle, use
setRetainInstance()
to tell Android it doesn't need to destroy and create the fragment.
Get Pro Android 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.