Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The Android ViewModel is not directly tied to the Fragment's lifecycle. The ViewModel is instead tied to the activity or the process, depending on how it was created. When a Fragment is destroyed and recreated due to a configuration change, such as a screen rotation, the same ViewModel instance is retained and reattached to the new Fragment instance. This helps to prevent data loss and ensure that the ViewModel can continue to provide data and state management for the UI components even after configuration changes occur.