Search code examples
xamarinandroid-activityxamarin.android

MainActivity.OnActivityResult(int, Result, Intent)': no suitable method found to override in Xamrine


I am trying to create project in xamarin but it causes error when i try to use method in mainactivity.cs file in Xamarin.android project -

protected override void onActivityResult(int requestCode, int resultCode, Intent data)
{
}

Error is :

MainActivity.OnActivityResult(int, Result, Intent)': no suitable method found to override

Solution

  • From Activity.OnActivityResult(Int32, Result, Intent) Method , we can see that the signature for Android.App.Activity.OnActivityResult is

    [Android.Runtime.Register("onActivityResult", "(IILandroid/content/Intent;)V", "GetOnActivityResult_IILandroid_content_Intent_Handler")]
    protected virtual void OnActivityResult (int requestCode, Android.App.Result resultCode, Android.Content.Intent data);
    

    So we have to override that to receive the activity result like

     protected override void OnActivityResult(Int32 requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
    
            // add some code you like 
        }