`observe(this, ...)` observes with the Fragment's lifecycle, which can remain active after the Fragment's view has been destroyed. When the LiveData emits while navigating back or while the Fragment is stopped, the callback may access a dead ViewBinding or other destroyed view state, causing the crash. Observe from `onViewCreated` with `viewLifecycleOwner`: ```kotlin override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) viewModel.d...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-legacy-state --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Android Legacy State?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-legacy-state-80175eb4)More formats (shields.io, HTML) on the badges page.
`observe(this, ...)` observes with the Fragment's lifecycle, which can remain active after the Fragment's view has been destroyed. When the LiveData emits while navigating back or while the Fragment is stopped, the callback may access a dead ViewBinding or other destroyed view state, causing the crash.
Observe from `onViewCreated` with `viewLifecycleOwner`:
```kotlin
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.data.observe(viewLifecycleOwner) { data ->
binding.title.text = data.title
binding.progressBar.isVisible = data.isLoading
}
}
```
The observer is then automatically removed when the Fragment's view lifecycle is destroyed and recreated for the next view instance. Do not use `observe(this, ...)` for UI updates in a Fragment. For new Flow-based code, collect with `viewLifecycleOwner.lifecycleScope` and `viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED)` instead.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!