nextcloud-deck icon indicating copy to clipboard operation
nextcloud-deck copied to clipboard

Zombie fragments after system initiated process death

Open stefan-niedermann opened this issue 4 years ago • 1 comments

Cause

After Android did a system initiated process death, the app throws errors after opening it again. This is, because there are still all Fragments intact and Android only killed the corresponding Activity. After recreating the Activity, there will be new Fragments (which work fine), but also the old Fragments still exist with an empty ViewModel.

Reproduce

  1. Run App with :arrow_forward: Play button
  2. Press :black_circle: Home button of android (center)
  3. Press :stop_button: Stop button in Android Studio
  4. Press :black_square_button: App switcher in Android
  5. Go back to the app
  6. Crash because ViewModel did not survive the System initiated process death

Solution

Simplest solution seems to be to remove() all old Fragments in the onStop method. They won't be available after recreating the Activity, and the Activity will reinstantiate new Fragments.

stefan-niedermann avatar May 10 '20 06:05 stefan-niedermann

Current solution has bad side effects. Needs further investigation.

Maybe somewhere references to the fragments are hold.

https://stackoverflow.com/questions/9727173/support-fragmentpageradapter-holds-reference-to-old-fragments/9745935#9745935

stefan-niedermann avatar May 17 '20 07:05 stefan-niedermann