Android activities go through an entire lifecycle when the device's orientation changes. In this video, learn how to restore an activity's state after a change in orientation.
- [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 …
Looking for study partners?Join the Associate Android Developer Exam study group
The Android app architecture constantly evolves. The introduction of the Kotlin programming language, new form factors such as Chromebooks, and reusable architecture components have made it faster and easier than ever to build high-quality Android apps. It is imperative that developers understand what the latest tools and recommendations are and how to use them to build out their applications. In this course, instructor David Gassner explains how to build an Android app that uses Kotlin instead of Java, add navigation functionality, and leverage the most useful architecture components such as LifecycleObserver, ViewModel, and LiveData, to create apps that are robust and easy to maintain over time.
- Handling lifecycle events
- Handling view events
- Updating display from new data
- Adding ViewModels to activities
- Subscribing to changes in LiveData values
- Adding a new launcher activity
- Starting activities with explicit intents
- Sharing data with implicit intents
- Adding a navigation drawer
- Adding a header to a navigation drawer
- Handling navigating drawer menu events