From the course: Android Development Essential Training: App Architecture with Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Restore state after orientation change

Restore state after orientation change - Android Tutorial

From the course: Android Development Essential Training: App Architecture with Kotlin

Start my 1-month free trial

Restore state after orientation change

- [Instructor] When a device's orientation changes from portrait to landscape, it's known as a configuration change. There are many sorts of configuration changes in Android but they all result in destroying and recreating the activity in memory. That means that the activity goes through an entire life cycle each time with calls to uncreate, undestroy and other life cycle functions. This can result in loosing state. So for example, if I roll the dice on my application and I see a randomized set of dice and then I turn the device, I loose the state and I see my default values again. You can fix this through use of something called the saved instance state bundle. This is a bundle that's passed into the uncreate function as the activity is restored. You can add values to this bundle as the activity shuts down and then restore those values as it comes back. A bundle is a set of key value pairs. So to track these value correctly you need a set of keys which are usually declared as…

Contents