From d6a33fb793bf4f73d7f4e888ab1d7a3e26170d26 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Mon, 24 Jun 2024 10:41:27 +1000 Subject: [PATCH] Override create window to fix android crash --- App.xaml.cs | 8 +++++++- Platforms/Android/MainActivity.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index fb489ea..33ae922 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -3,10 +3,16 @@ public App(NavigatorService navigatorService) { InitializeComponent(); - MainPage = new AppShell(); + //MainPage = new AppShell(); NavigatorService = navigatorService; } internal NavigatorService NavigatorService { get; private set; } + + protected override Window CreateWindow(IActivationState? activationState) { + // always create new windows. This allows share intents to not crash on android + // (with the side effect that multiple windows are opened, which is messy but better than a crash) + return new Window(new AppShell()); + } } } diff --git a/Platforms/Android/MainActivity.cs b/Platforms/Android/MainActivity.cs index fd1a494..18f65a8 100644 --- a/Platforms/Android/MainActivity.cs +++ b/Platforms/Android/MainActivity.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection; using Neighbourhood.omg.lol.Models; namespace Neighbourhood.omg.lol { - [Activity(Theme = "@style/Maui.SplashTheme", LaunchMode = LaunchMode.SingleTop, MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] + [Activity(Exported = true, Theme = "@style/Maui.SplashTheme", LaunchMode = LaunchMode.SingleTop, MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] [IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], DataMimeType = "text/plain")] [IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], DataMimeType = "*/*")] public class MainActivity : MauiAppCompatActivity {