Upgrade to Pro — share decks privately, control downloads, hide ads and more …

State Restoration - The Full Picture (With Coroutines)

State Restoration - The Full Picture (With Coroutines)

One of the stated goals of Android Architecture Components is to make it easier for developers to manage the lifecycle of application components. However, when looking at the full picture of combining configuration changes and background memory constraints with static and dynamic state, the basic examples provided in the documentation begin to show their limitations. A more in-depth exploration is needed.

We'll look at how to combine bundles and view models to fully persist the state of the application during its lifecycle. Using coroutines for concurrency, we'll see how dynamic state restoration can be achieved.

Going over increasingly complex examples of state restoration constraints, we'll see how our implementation of state restoration grows and evolves.

Presented at Android Makers 2019: https://androidmakers.fr/schedule/2019-04-24?sessionId=JJK-6338
Code: https://github.com/MartinDevi/android-makers-2019-state-restoration--the-full-Picture-with-coroutines

Martin Devillers

April 24, 2019
Tweet

More Decks by Martin Devillers

Other Decks in Programming

Transcript

  1. ACTIVITY CONFIGURATION CHANGES ▸ density ▸ fontScale ▸ keyboard ▸

    keyboardHidden ▸ layoutDirection ▸ locale ▸ mcc ▸ mnc ▸ navigation ▸ orientation ▸ screenLayout ▸ screenSize ▸ smallestScreenSize ▸ touchscreen ▸ uiMode
  2. DEPENDING UPON THE ACTION A USER TAKES, THEY EITHER EXPECT

    THAT ACTIVITY STATE TO BE CLEARED OR THE STATE TO BE PRESERVED. IN SOME CASES THE SYSTEM AUTOMATICALLY DOES WHAT IS EXPECTED BY THE USER. IN OTHER CASES THE SYSTEM DOES THE OPPOSITE OF WHAT THE USER EXPECTS. STATE RESTORATION
  3. STATE RESTORATION TAKEAWAYS ▸ Assess user expectations correctly, so that

    you don’t do too much work ▸ Look for the upcoming androidx.lifecycle enhancements, which should be very useful ▸ Be careful to not leak context in coroutines launched within ViewModel ▸ Build more tools to simplify task?