Skip to content

fix: prevent crash on exit from double unbindService when Stop Music on Task Clear is enabled#772

Open
mvanhorn wants to merge 1 commit into
vivizzz007:mainfrom
mvanhorn:fix/647-fix-crash-on-exit-when-stop-music-on-tas
Open

fix: prevent crash on exit from double unbindService when Stop Music on Task Clear is enabled#772
mvanhorn wants to merge 1 commit into
vivizzz007:mainfrom
mvanhorn:fix/647-fix-crash-on-exit-when-stop-music-on-tas

Conversation

@mvanhorn

Copy link
Copy Markdown

🚀 What does this PR do?

With "Stop Music on Task Clear" enabled, exiting the app crashes with java.lang.IllegalArgumentException: Service not registered from MainActivity.onDestroy -> unbindService. The same crash is reported in #771 and #737.

The cause is a double unbindService on the same serviceConnection. onStop() already unbinds unconditionally, and onDestroy() unbinds again inside the StopMusicOnTaskClearKey && isPlaying && isFinishing branch. Since onStop() runs before onDestroy(), the connection is already gone and the second call throws.

This adds a serviceBound flag set when bindService succeeds in onStart() and guards both unbindService call sites so each unbind matches exactly one bind. stopService() and clearing playerConnection are unchanged.

📸 Screenshots / Recordings

n/a (crash fix, no UI change)

🛠️ Checklist

📝 Additional Notes

Change is local to MainActivity.kt and is a small bind-state guard.

Fixes #647

@mvanhorn mvanhorn mentioned this pull request Jun 28, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Stop Task on Clear

1 participant