tezvyn:

How do you share a ViewModel between Fragments?

Source: developer.android.comintermediate

Tests your understanding of ViewModel lifecycle scoping beyond a single screen. To share, scope the ViewModel to the parent Activity or a navigation graph using `activityViewModels()` or `navGraphViewModels()`.

This tests your knowledge of modern Android architecture and ViewModel lifecycle scoping for inter-fragment communication. A senior answer specifies scoping the ViewModel to a shared owner, like the parent Activity (`activityViewModels()`) or a navigation graph (`navGraphViewModels()`). Mention observing LiveData/StateFlow for updates. A red flag is suggesting outdated patterns like `setTargetFragment` or using global singletons, which ignore lifecycle safety.

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

How do you share a ViewModel between Fragments? · Tezvyn