2016-12-20 8 views
1

アプリを閉じると「アクティビティが破棄されました」という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(); 
    } 
} 
+0

'GC.Collect();'の行はおそらくこれを引き起こしますか? –

+0

@GeraldVersluisいいえ、残念ながらそうではありません。それは問題を解決しようとしたが、成功しなかった。私は 'GC.Collect();'行をコメントアウトしてみましたが、例外はまだあります。 – Zero

+0

アプリを終了するか、もう一度開いたことはありますか?同様の問題を持つXamarin Forumsの[this thread](https://forums.xamarin.com/discussion/72954/java-lang-illegalstateexception-activity-has-been-destroyed-on-pageradapter)を参照してください。 –

答えて

2

[OK]を、それはバグでしたXamarin.Formsバージョン2.3.3.175。このバグを修正するには、以前のバージョンのXamarin.Formsをインストールします。私のアプリはバージョン2.3.0.107で動作します。

バージョン2.3.3.175のバグは、バージョン2.3.4-pre1で修正する必要があります。

+1

2.3.4-pre1でも同じことが起こる – Levvy

+0

xamarinはバージョン2.3.4-pre1で修正されないかもしれない:(私はバージョン2.3.2.127このバグはありません – Zero

+0

バージョン2.3.4-pre1をテストしましたが、バグはありません – Zero

関連する問題