maui
maui copied to clipboard
Maui App using R8 & MauiHybridWebView crashes whenever it is killed in background by Android and then restarted by OS
UPDATE
I was able to figure out this is a MauiHybridWebView issue. Any project with that added displays this crash behavior when also built with R8.
I posted another bug report here with more details and a reproduction project: https://github.com/Eilon/MauiHybridWebView/issues/66
Description
Maui Crash Behavior
I have been observing a behavior which I am having a hard time figuring out the meaning of or how to investigate or fix it:
- Maui App is running fine in Android.
- Switch to another application while leaving Maui App running in background or turn off phone screen for very long time (typically hours but unpredictable).
- Attempt to return to Maui App from Android application carousel.
- Rather than loading back into already running Maui App directly, Android goes to splash screen for app again (ie. restarts it), then immediately this fails and it crashes the app, closing it completely.
Android Lifecycle
Having reviewed the Android lifecycle here: https://stackoverflow.com/questions/4267897/what-happens-to-activities-services-when-phone-goes-to-sleep-standby-mode#4268025
I suspect what is happening is that when the phone is idle or doing other things long enough, it eventually runs onStop() to free the resources killing the active app.
Then when you navigate back to the "open" app it runs onCreate() or onRestart(). At this point it briefly shows the splash screen again, but this time the creation or starting of app fails and it crashes.
Investigation/Solution?
The problems I have in trying to find out what is causing this (and whether Maui code problem or mine) are:
- No way to reliably trigger this process to happen - Android shuts it down and triggers this restart on its own whims. Any way to manually force this process to occur?
- No way to debug what happens during this - Usually from Visual Studio I can debug to my device or the emulator, but since I have no way to reliably trigger the problem, and the debugger seems to detach when the app is closed, I don't know how to see the problem.
Would loading the APK in Android Studio offer any special tools to figure out what is happening? Any suggestions?
Thanks.
Steps to Reproduce
Unpredictable. Leave app running with phone screen off or doing other activities in other apps. Several hours later, if OS likely has stopped it in background, attempting to return to it will trigger the splash screen momentarily and then it will crash and not resume.
Link to public reproduction project repository
n/a
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Open similar issues:
- Android : Maui rc-1 crash on android (#17697), similarity score: 0.79
- Maui application does not restart properly after android activity is destroyed (#18845), similarity score: 0.79
- App crashes when navigating after the app has been in the background (#12553), similarity score: 0.76
Closed similar issues:
- MAUI clearing storage of app (#6641), similarity score: 0.77
- MAUI Android build crashes when app is reopened from background. It throws the exception: 'Window was already created.' (#18692), similarity score: 0.76
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Can you attach a logcat file with your crash? https://learn.microsoft.com/en-us/xamarin/android/deploy-test/debugging/android-debug-log?tabs=windows
I was able to figure out this is a MauiHybridWebView issue. Any project with MauiHybridWebView added displays this crash behavior when also built with R8 in Android. @Eilon
I posted another bug report here with more details and a reproduction project/instructions: https://github.com/Eilon/MauiHybridWebView/issues/66
Duplicate of https://github.com/Eilon/MauiHybridWebView/issues/66