2017-08-30 69 views
0

我在使用xamarin表單的時候,當我在主頁上的時候出現了andorid,並且我從錯誤'未處理的異常發生後點擊了它。不遵循應用生命週期OnBackPressed()xamarin表單中的錯誤

我試圖做這種方式,沒有結果至今(OnBackPressed)

[Activity(Label = "teste", Icon = "@drawable/icon", Theme = "@style/MainTheme", NoHistory = true, MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     TabLayoutResource = Resource.Layout.Tabbar; 
     ToolbarResource = Resource.Layout.Toolbar; 

     base.OnCreate(bundle); 

     global::Xamarin.Forms.Forms.Init(this, bundle); 
     LoadApplication(new App()); 

    } 
    bool formOpen = false; 
    void OnBackPressed(Bundle bundle) 
    { 
     if (formOpen == false) 
     { 
      base.OnBackPressed(); 
     } 
     else 
     { 

     } 
    } 
} 

回答

0

OnBackPressed應標記爲override,它是public

public override void OnBackPressed() 
{ 
    if (!formOpen) 
     base.OnBackPressed(); 
    else 
    { 

    } 
} 
+0

無論哪種方式,它給人的錯誤時,返回 –

+0

它崩潰中的其他和發生錯誤,我認爲它不允許在後臺 –

+0

應用這種情況發生時,我 –

0

使用下面

protected override bool OnBackButtonPressed() 
    { 
     return base.OnBackButtonPressed(); 
    } 

Xamarin形成頁面,而不是在android活動中。

+0

沒有成功,離開錯誤應用程序時出現同樣的錯誤 –