A small diagnostics screen shows the device’s current audio route in a TextView and writes a short event history in a RecyclerView. After a recent PR, the screen started behaving unstably: after reopening it, the history sometimes grows faster than expected, and route changes can cause crashes on some devices. Need to find the causes from the diff and behavior description.
Fragment is visible.RecyclerView and TextView updates must happen safely on the UI thread.RouteMonitorFragment.simulateHeadset() button in the debug environment or by connecting/disconnecting a headset.Additional steps for the second symptom:
View is destroyed, the old screen instance stops receiving callbacks.RecyclerView or TextView from a non-UI thread.kotlinx.coroutines:1.8.11.8.2, Lifecycle 2.8.4, RecyclerView 1.3.2Fragment with View Binding, without ComposeRouteRepository is a process-wide singleton that survives Fragment recreationUse line comments to explain the problem, its impact, the fix and how to test it.