From the course: Building an Android App with Jetpack Libraries

Unlock the full course today

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

Maintain note selections through configuration changes

Maintain note selections through configuration changes - Android Tutorial

From the course: Building an Android App with Jetpack Libraries

Start my 1-month free trial

Maintain note selections through configuration changes

- [Instructor] My last step is to handle configuration changes in the main fragment, where an orientation change causes the loss of note selection state. For example I can select a couple of note here for deletion and then when I rotate the device I lose that selection. And that's because the adapter object is being used to save the selection state and that adapter object is being destroyed and recreated as the orientation changes. To fix this I'll once again use the saved instance state. This time I'm going to save my arraylist of note entity objects. but there's a bit of a complication. In order to save complex objects like note entity, they have to implement the Parcelable interface. If I were programming in Java, that would take a lot of boiler plate code with specific references to the classes properties, but in Kotlin you just need an annotation and a return type. To use this annotation I need to add a declaration in…

Contents