MetroList: Stop Music When Task is Cleared
Scritto da Alessio il 06/04/2026
Problem
Music continued playing after the user swiped MetroList from the recents screen. The app relied solely on onDestroy() to stop playback, but onDestroy() isn't always invoked when the system clears the task.
Solution
Implemented onTaskRemoved() callback in MusicService instead of MainActivity (Activities don't have this method). onTaskRemoved() is specifically called when the user swipes the app away from recents.
Added handling for buffering state where playWhenReady is true but isPlaying is false. Simplified to player.stop() and stopSelf().
Result
Music stops reliably when the app is cleared from recents, regardless of Android version or system behavior.
Commit: MetrolistGroup/Metrolist@1e0a3ec
PR: #3456