アプリを閉じると「アクティビティが破棄されました」というIllegalStateExceptionが発生します。私App.csでxamarinアプリの終了時にIllegalStateExceptionアクティビティが破棄されました
私は公共の静的なマスターページを宣言:
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;
}
}
そして、私はマスターとDetilPageを宣言MasterPage.cs中:
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();
}
}
'GC.Collect();'の行はおそらくこれを引き起こしますか? –
@GeraldVersluisいいえ、残念ながらそうではありません。それは問題を解決しようとしたが、成功しなかった。私は 'GC.Collect();'行をコメントアウトしてみましたが、例外はまだあります。 – Zero
アプリを終了するか、もう一度開いたことはありますか?同様の問題を持つXamarin Forumsの[this thread](https://forums.xamarin.com/discussion/72954/java-lang-illegalstateexception-activity-has-been-destroyed-on-pageradapter)を参照してください。 –