Fix Android App Exit On Back button pressed #2145
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional 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 callingandroid: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.