Brifing

Two Bugs, One Setting: How DKA Silently Broke Our Fragments

ProAndroidDev - Medium1 min

1DKA and Fragment Recreation

The DKA (Don't Keep Activities) option in Android Developer Options causes the system to destroy an activity when the user navigates away from it. Fragments are also destroyed, but ViewModels are retained by ViewModelStore. When the activity is recreated, the fragment is re-instantiated while the ViewModel is reused. This results in custom onCreate-like methods tied to the ViewModel lifecycle not running again.

2onCreateFeature in MVI Architecture

In MVI architecture, there is a method called onCreateFeature(bundle, savedState) similar to ViewModel.onCreate(). This is where the feature engine, reducer, and all delegates are created. onCreateFeature runs exactly once when the ViewModel is first created. When the fragment is recreated and the ViewModel is reused, onCreateFeature does not run again. This means that everything initialized in the previous fragment instance remains intact.

Original article: ProAndroidDev - Medium — Android'de DKA ve Fragment Sorunları