Reputation: 61
Launching app with attached debbuger. Moving the app in background the app crash with following error:
[0:] An error occurred: 'Window was already deactivated'. Callstack: ' at Microsoft.Maui.Controls.Window.Microsoft.Maui.IWindow.Deactivated()
at Microsoft.Maui.LifecycleEvents.AppHostBuilderExtensions.<>c.<OnConfigureLifeCycle>b__2_4(UIApplication app)
at Microsoft.Maui.MauiUIApplicationDelegate.<>c__DisplayClass15_0.<OnResignActivation>b__0(OnResignActivation del)
at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[OnResignActivation](IServiceProvider services, Action`1 action)
at Microsoft.Maui.MauiUIApplicationDelegate.OnResignActivation(UIApplication application)
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
at CFFTCheckInMobile.Program.Main(String[] args) in D:\CheckInMobile\CheckInMobile\Platforms\iOS\Program.cs:line 13
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)'
The app has been terminated.
After the error, the app restart and then the error never appear.
Platforms\iOS\Program.cs ha the following code:
public class Program
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
The app.xaml.cs has the following code
public partial class App : Application
{
public static readonly Api Api = new();
public static readonly Functions Functions = new();
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new LoadingPage());
}
The loadingpage has a viewmodel with following code:
public async Task LoadingTask()
{
try
{
using (await loading.Show())
{
.............
((App)Application.Current).MainPage = new NavigationPage(new MainPage(true));
}
}
When i try to move the app in background the app is showing "MainPage"
The "await loading.Show()" is using mopups
Any ideas ?
Removing the code "((App)Application.Current).MainPage = new NavigationPage(new MainPage(true));" but nothing change.
Upvotes: 2
Views: 740
Reputation: 61
i found a solution for same issue here: https://github.com/LuckyDucko/Mopups/issues/95
public override void OnActivated(UIApplication application)
{
(application.ConnectedScenes.AnyObject as UIWindowScene)?.Windows.FirstOrDefault()?.MakeKeyWindow();
base.OnActivated(application);
}
public override void OnResignActivation(UIApplication application)
{
(application.ConnectedScenes.AnyObject as UIWindowScene)?.Windows.FirstOrDefault()?.MakeKeyWindow();
base.OnResignActivation(application);
}
Your solution is similar. Thanks
Upvotes: 4
Reputation: 1
You can resolve this issue with this, on AppDelegate, you can apply it to your needs.
public override void OnActivated(UIApplication application)
{
try
{
base.OnActivated(application);
}
catch (Exception ex)
{
}
}
}
}
Upvotes: 0
Reputation: 61
Solved. I removed using (await loading.Show());
declaration from LoadingPage.
Upvotes: 0