~/talk

When ViewModels Go to Die: Saving ViewModel State

Talkat droidcon Americas 2020 · 2020-11-16..11-17· [android, testing]
links:none on file
slides:none on file

Explains how Jetpack SavedStateHandle lets a ViewModel persist transient UI state across system-initiated process death rather than using persistent storage; demo builds a tiny app, adds dependency lifecycle-viewmodel-savedstate:2.2.0, replaces manual Bundle plumbing with constructor-injected SavedStateHandle, initializes via SavedStateViewModelFactory (or a custom AbstractSavedStateViewModelFactory for extra args), and proves survival with an adb shell am kill test; notes limits: only small/parcelable data and risk of “transaction too large,” and it doesn’t restore after user force-close.

AI-written summary · about

  1. 0:00Introduction and welcome
  2. 0:53About the speaker
  3. 1:34What is state in Android
  4. 2:16State vs activity lifecycle
  5. 3:18ViewModels and state management
  6. 4:01Process death and its impact
  7. 5:03Resource constraints and process death
  8. 6:04ViewModels and process death loss
  9. 7:07Real-world implications of process death
  10. 8:12Live coding demo setup
  11. 9:38Simulating process death with ADB
  12. 10:20Limitations of saved instance state
  13. 11:23How saved instance state works
  14. 12:47Problems with saved instance state
  15. 13:30Introducing saved state handle
  16. 14:32Benefits of saved state handle
  17. 15:14Making app process death proof
  18. 15:56Adding saved state handle dependency
  19. 16:17Updating ViewModel with saved state
  20. 17:43ViewModel factory setup
  21. 18:28Initializing ViewModel with factory
  22. 19:34Testing process death survival
  23. 21:01Handling constructor arguments
  24. 22:04Creating custom ViewModel factory
  25. 23:30Updating fragment with custom factory
  26. 24:13How saved state handle works behind scenes
  27. 26:44ViewModel and view responsibilities
  28. 27:26Limitations of saved state handle
  29. 28:08Benefits for developers and users
  30. 28:30Q&A session begins
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.