Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Android App Exit On Back button pressed #2145

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

ne0rrmatrix
Copy link
Contributor

  • Bug fix

Description of Change

In Android service destroy method the app was exiting. I removed the app exit method calls and now the destroy method only shuts the service down. This is still required as pressing back button to exit page should close service.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

I had put a call to exit app in the Destroy method for Android notification service and did not realize the back button would call it. It has been removed now. I tested against the provided sample and the app does not close when pressing back button in Android now. I kept the call to end service when you leave page.

I need that to be there for lifecycle behavior when app is restored from being killed by OS it is retaining state when it should not. This Platform.CurrentActivity?.StopService(new Intent(Platform.AppContext, typeof(MediaControlsService))); line of code that is now in destroy method in collaboration with calling android:stopWithTask="true" in manifest file prevents the app from restoring. I like the idea of app restore but many developers complained about this not being expected.

Removed logging and explicit termination calls from OnDestroy
method in MediaControlsService.android.cs. This change aims to
allow for a more graceful shutdown process and avoid abrupt
termination of the application.
@ne0rrmatrix ne0rrmatrix added the 📽️ MediaElement Issue/PR that has to do with MediaElement label Aug 21, 2024
@ne0rrmatrix ne0rrmatrix self-assigned this Aug 21, 2024
@brminnick brminnick merged commit a4762f7 into CommunityToolkit:main Aug 21, 2024
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📽️ MediaElement Issue/PR that has to do with MediaElement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] MediaElement Android .NET8 crashing
3 participants