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 - Android Tutorial
From the course: Android Development Essential Training: App Architecture with Kotlin
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
-
-
-
-
(Locked)
Work with synthetic view bindings5m 10s
-
(Locked)
Get view references with findViewById()4m 53s
-
(Locked)
Handle view events with lambdas5m 26s
-
(Locked)
Create companion object functions6m 16s
-
(Locked)
Update display from new data4m 47s
-
(Locked)
Restore state after orientation change7m 10s
-
(Locked)
Add a ViewModel to an activity4m 43s
-
(Locked)
Subscribe to changes in LiveData values7m 57s
-
(Locked)
-
-
-