Reputation: 266
I am trying to do exercises in xamarin to learn it. The error I am getting is onbackpressed no suitable method found to override. I'm either missing an assembly reference or using statement at top, or I am putting this override in the wrong spot. Can anybody give me a hand? Thanks
using System;
using Android.Webkit;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Text;
using Android.Net;
using Java.Interop;
namespace myNamespace
{
[Activity (Label = "myapp", MainLauncher = true, Icon = "@drawable/icon", Theme = "@android:style/Theme.NoTitleBar")]
public class MainActivity : Activity
{
bool formOpen = false;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var webview = new WebView(this);
webview.Settings.JavaScriptEnabled = true;
webview.Settings.SetGeolocationEnabled(true);
webview.AddJavascriptInterface (new MyJSInterface (this), "C");
webview.SetWebViewClient(new MyWebViewClient(this));
webview.SetWebChromeClient(new MyWebChromeClient(this));
SetContentView(webview);
webview.LoadUrl ("http://example.com");
}
public override void onBackPressed() {
if (formOpen == false) {
base.OnBackPressed();
}
}
}
}
Upvotes: 1
Views: 1562
Reputation: 89102
the method signature is protected override void OnBackPressed()
Note that Xamarin uses C# naming conventions, so the method starts with a capital "O"
Upvotes: 1