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 editor state through configuration changes

Maintain editor state through configuration changes - Android Tutorial

From the course: Building an Android App with Jetpack Libraries

Start my 1-month free trial

Maintain editor state through configuration changes

- [Tutor] My app is almost complete, but I have to take care of one important scenario. Configuration changes, such as switches from portrait to landscape orientation can disrupt the state of the application. I have issues in both fragments right now, but I'm going to start with the editor fragment. If I select a note and then add some changes, and then rotate the device, those changes are lost. And that's because the view model is maintaining the state of the note entity object, and it's republishing it when the configuration change happens. So I have to add conditional code to handle that. So the user sees a constant state in the editor. I'm going to use savedInstanceState to do this. And for that, I'll need some constants to use as keys in key value pairs. I'll go to my constants class, and I'm going to add two new constants. The first one will be called NOTE_TEXT_KEY and that's a string value and it can be anything .…

Contents