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

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

Closed
jonmdev opened this issue May 23, 2024 · 4 comments
Labels
area-controls-hybridwebview HybridWebView control area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@jonmdev
Copy link

jonmdev commented May 23, 2024

UPDATE

I was able to figure out this is a MauiHybridWebView issue. Any project with a MauiHybridWebView added crashes when the OS restarts it if it was also built to Android with R8.

I posted another bug report here with more details and a reproduction project/instructions: Eilon/MauiHybridWebView#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 jonmdev added the t/bug Something isn't working label May 23, 2024
@jonmdev jonmdev changed the title Maui App crashes whenever it is killed in background in Android and then restarted by OS. How to investigate or solve? Maui App crashes whenever it is killed in background by Android and then restarted by OS. How to investigate or solve? May 23, 2024
Copy link
Contributor

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.

@PureWeen
Copy link
Member

@PureWeen PureWeen added platform/android 🤖 area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events s/needs-info Issue needs more info from the author labels May 23, 2024
@jonmdev
Copy link
Author

jonmdev commented May 24, 2024

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: Eilon/MauiHybridWebView#66

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels May 24, 2024
@jonmdev jonmdev changed the title Maui App crashes whenever it is killed in background by Android and then restarted by OS. How to investigate or solve? Maui App using R8 & MauiHybridWebView crashes whenever it is killed in background by Android and then restarted by OS May 24, 2024
@Eilon Eilon added the area-controls-hybridwebview HybridWebView control label May 24, 2024
@ninachen03 ninachen03 added s/triaged Issue has been reviewed and removed s/triaged Issue has been reviewed labels May 27, 2024
@mattleibow
Copy link
Member

Duplicate of Eilon/MauiHybridWebView#66

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-hybridwebview HybridWebView control area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants