Open reinhardlackner opened 3 months ago
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!
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
@Eilon thoughts?
Hi @reinhardlackner - this sounds like an issue that many people have run into and we made a recent patch to .NET MAUI 8 where you can enable a workaround for this issue. See https://github.com/dotnet/maui/pull/22496 for full details.
If you are encountering hangs in Android with BlazorWebView, you can enable this AppContext Switch with one line of code in your app's MauiProgram.cs
:
AppContext.SetSwitch("BlazorWebView.AndroidFireAndForgetAsync", isEnabled: true);
Make sure you're updated to the latest patch of .NET MAUI, and try out this switch. If it resolves your issue (or not!), please let us know.
Hi @Eilon Unfortunately, this does not solve the issue because AppContext.SetSwitch("BlazorWebView.AndroidFireAndForgetAsync", isEnabled: true); causes a reload of the whole blazor webview. Same result for MAUI version 8.0.71 (=latest) and 8.0.61 - set in csproj file:
E.g. when you open the "Counter" page and connect to a Bluetooth keyboard, the WebView reloads instead of being black (=> the whole app is reloaded - you are on the "Home" page again) and the state is lost.
Video:
https://github.com/user-attachments/assets/c3a1fe78-ccf5-4b01-9756-414da8ad84ca
@Eilon @mattleibow Please reopen this issue because it's not resolved.
@reinhardlackner alright issue is re-opened so we can investigate further.
Can you confirm if this is all true:
If that's true, then this might have to do with Android restarting the "Activity" that the page is associated with, which then causes it to re-load and start over again.
I'll need to find someone more knowledgeable about Android specifics to understand if there's something BlazorWebView can do to avoid being completely restarted.
@reinhardlackner alright issue is re-opened so we can investigate further.
Can you confirm if this is all true:
- Initially the app was hanging when connecting the Bluetooth keyboard
- With the patch and switch enabled, the app does not hang anymore, but it refreshes the page (sort of like it resets)
If that's true, then this might have to do with Android restarting the "Activity" that the page is associated with, which then causes it to re-load and start over again.
I'll need to find someone more knowledgeable about Android specifics to understand if there's something BlazorWebView can do to avoid being completely restarted.
@Eilon Thanks for reopening. I can confirm that this is true (1+2). 2: And after the implementation of AppContext.SetSwitch("BlazorWebView.AndroidFireAndForgetAsync", isEnabled: true) the refresh of the browser seems to be a restart of the main activity.
@reinhardlackner thank you for confirming.
Description
If you open a MAUI Blazor app and connect a bluetooth keyboard on a real device, the app gets black. You can't use the app any more until you restart it.
Steps to Reproduce
Create new .NET MAUI Blazor Hybrid app (net8) in Visual Studio
Deploy it to a real Android device (tested with Samsung Galaxy Tab S6 Lite and Samsung Galaxy Tab S7 FE)
Disable bluetooth on the Android device
Start the app
Activate bluetooth and connect to a bluetooth keyboard
App gets black immediately after bluetooth keyboard was connected and you can no longer work with the app. Also switching between the Android apps does not help (purple background color - app does not work) - you really need to close the app and to restart it - after that, working with the app is possible again
Full video with described repo steps:
https://github.com/user-attachments/assets/4e4a29f8-506a-4705-b098-add8bd37570e
Link to public reproduction project repository
No response
Version with bug
8.0.61 SR6.1
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 14 with OneUI version 6.1
Did you find any workaround?
No response
Relevant log output