maui icon indicating copy to clipboard operation
maui copied to clipboard

Maui App using R8 & MauiHybridWebView crashes whenever it is killed in background by Android and then restarted by OS

Open jonmdev opened this issue 1 year ago • 4 comments

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

android lifecycle

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

jonmdev avatar May 23 '24 00:05 jonmdev

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:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar May 23 '24 00:05 github-actions[bot]

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

PureWeen avatar May 23 '24 18:05 PureWeen

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

jonmdev avatar May 24 '24 02:05 jonmdev

Duplicate of https://github.com/Eilon/MauiHybridWebView/issues/66

mattleibow avatar May 30 '24 16:05 mattleibow