Overview › Lifecycle Issues
Fragment / Activity Lifecycle Issues
Fragment-detach crashes, leaked listeners, view-binding access after onDestroyView, observer scope mismatches, and fragment-transaction state-loss patterns. These are the most common production crash sources in Android apps.
13
CRITICAL
Critical
13
High
20
Medium
0
Hot files
15
distinct files
Lifecycle pitfalls covered
| Pattern | Risk | Fix |
|---|---|---|
getActivity() in callback | NPE if fragment detached | Guard with isAdded(), capture activity early |
observe(this) in fragment | Observer outlives view; double-render after rotation | Use viewLifecycleOwner |
_binding!! after onDestroyView | NPE in async callback | Guard with _binding?.let { … } |
addOnGlobalLayoutListener never removed | View-tree leaks fragment | Pair with removeOnGlobalLayoutListener in onDestroyView |
commitAllowingStateLoss() after onSaveInstanceState | Hides bugs; lost UI state | Wrap in if (!isStateSaved), queue otherwise |
Handler() as anonymous inner class | Holds outer fragment ref | Use static handler + WeakReference, or coroutines |
NetworkCallback not unregistered | Fires after detach → NPE | Unregister in onDestroyView |
Costco Android · Code Review Report · Generated 2026-05-07 · 626 machine-curated findings