gpt4 book ai didi

android - xamarin IllegalStateException Activity 已在应用程序关闭时被销毁

转载 作者:行者123 更新时间:2023-11-29 19:26:38 25 4
gpt4 key购买 nike

当我关闭我的应用程序时,我收到“Activity 已被销毁”的 IllegalStateException。

在我的 App.cs 中,我声明了一个公共(public)静态 MasterPage:

protected override void OnStart()
{
// Handle when your app starts
if (Device.OS == TargetPlatform.Android)
{
Device.BeginInvokeOnMainThread(() =>
{
masterdetail = new MasterPage();
MainPage = masterdetail;
});
}
else
{
masterdetail = new MasterPage();
MainPage = masterdetail;
}
}

在 MasterPage.cs 中,我声明了 Master 和 DetilPage:

public partial class MasterPage : MasterDetailPage
{

public MasterPage()
{

var IsLoggedIn = false;

if (CrossSecureStorage.Current.HasKey("isLoggedIn"))
{
IsLoggedIn = string.Equals(CrossSecureStorage.Current.GetValue("isLoggedIn"), "true", System.StringComparison.CurrentCultureIgnoreCase);
}

Master = SetMasterContentPage();
if (IsLoggedIn)
{
Detail = new NavigationPage(new TaxonomyOverviewPage());
}
else {
Detail = new NavigationPage(new LoginPage());
}
}

ContentPage SetMasterContentPage()
{
var masterPage = new ContentPage { Title = "Test"};
masterPage.Content = new StackLayout
{
Children = {
new Label{Text="Label1"},
new Label{Text="Label2"},
new Label{Text="Label3"}
}
};

return masterPage;
}

protected override void OnDisappearing()
{
base.OnDisappearing();
GC.Collect();
}
}

最佳答案

好的,这是 Xamarin.Forms 版本 2.3.3.175 中的错误。若要修复此错误,请安装早期版本的 Xamarin.Forms。我的应用程序运行版本为 2.3.0.107。

2.3.3.175版本的bug应该在2.3.4-pre1版本中修复

关于android - xamarin IllegalStateException Activity 已在应用程序关闭时被销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41240031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com