Skip to content

Bind service based on Activity/Fragment lifecycle#133

Merged
chenxiaolong merged 1 commit into
masterfrom
exit-lifecycle
May 16, 2026
Merged

Bind service based on Activity/Fragment lifecycle#133
chenxiaolong merged 1 commit into
masterfrom
exit-lifecycle

Conversation

@chenxiaolong
Copy link
Copy Markdown
Owner

The service connection was previously associated with the ViewModel lifecycle, which breaks the exit button when the Activity or Fragment is stopped but not destroyed. In this state, the ViewModel would never be cleared, so it would remain bound to the service, preventing the service from exiting.

This commit moves the service connection logic out of the view models and into a dedicated DefaultLifecycleObserver that only maintains the connection while the lifecycle owner is in the started phase.

Fixes: #130

@chenxiaolong chenxiaolong self-assigned this May 16, 2026
@chenxiaolong chenxiaolong force-pushed the exit-lifecycle branch 2 times, most recently from 4cf490f to 675ee83 Compare May 16, 2026 19:05
The service connection was previously associated with the ViewModel
lifecycle, which breaks the exit button when the Activity or Fragment is
stopped but not destroyed. In this state, the ViewModel would never be
cleared, so it would remain bound to the service, preventing the service
from exiting.

This commit moves the service connection logic out of the view models
and into a dedicated DefaultLifecycleObserver that only maintains the
connection while the lifecycle owner is in the started phase.

Fixes: #130

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
chenxiaolong added a commit that referenced this pull request May 16, 2026
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
@chenxiaolong chenxiaolong merged commit 6e9bc74 into master May 16, 2026
1 check passed
@chenxiaolong chenxiaolong deleted the exit-lifecycle branch May 16, 2026 21:20
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.

Exit action not working

1 participant