title: Android Webview app crashes after selecting Contact with Contact picker
body: <p>I have a Mono Android Webview app (developed with c# VS2015).</p>
  
  <p>The issue I am facing at the moment, is that I am starting an ActionPick Intent to choose a contact in order to send a custom SMS. But once I select the contact from the list I am getting an "Object not set to an instance of an object" exception somehow in my OnActivityResult method.</p>
  
  <p>The important thing here is that I am calling this intent from a Javascript Interface class (this is how I am sending data from my website, inside the webview to my app). I'm guessing this has something to do with it, but I am at a loss, as I have try/catch blocks around everything and yet the app is still giving me "MyApp has stopped working" messages.</p>
  
  <p>It's calling the MainActivity ContactSMS() just fine, and bringing up the contact list.. I just seem to be handling the result of selecting a contact incorrectly. </p>
  
  <p>Thank you very much for any help/suggestions!</p>
  
  <p>Javascript Interface:</p>
  
  <pre><code>[JavascriptInterface, Export("contactsms")]
          public void ContactSMS()
          {
              try
              {
                  if (context.GetType() == typeof(MainActivity))
                      ((MainActivity)context).ContactSMS();
              }
              catch(Exception ex)
              {
                  Toast.MakeText(context, "Interceptor_ContactSMS: " + ex.Message, ToastLength.Short).Show();
              }
          } 
  </code></pre>
  
  <p>MainActivity:</p>
  
  <pre><code>public void ContactSMS()
          {
              try
              {
                  //Create a new intent for choosing a contact
                  var contactPickerIntent = new Intent(Intent.ActionPick, ContactsContract.Contacts.ContentUri);
                  //contactPickerIntent.SetType(ContactsContract.Contacts.ContentType);
  
                  //Start the contact picker expecting a result
                  // with the resultCode '101'                
                  StartActivityForResult(contactPickerIntent, 101);                    
              }
              catch(Exception ex)
              {
                  Toast.MakeText(instance.context, "MainActivity_ContactSMS: " + ex.Message, ToastLength.Short).Show();
              }
          }
  </code></pre>
  
  <p>OnActivityResult (<strong>This doesn't run - crashes before entering method</strong>):</p>
  
  <pre><code>protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
          {
              try
              {                
                  //See if we are handling the contact picker request code
                  //  and that the result code is ok!
                  if (requestCode == 101 &amp;&amp; resultCode == Result.Ok)
                  {
                    ...
                  }
  </code></pre>
  
  <p>Logcat from app crash:
  02-20 16:32:33.824  7348  7348 I MonoDroid: UNHANDLED EXCEPTION:</p>
  
  <p>02-20 16:32:33.846  7348  7348 I MonoDroid: System.NullReferenceException: Object reference not set to an instance of an object</p>
  
  <p>02-20 16:32:33.846  7348  7348 I MonoDroid:   at MyApp.MainActivity.OnActivityResult (Int32 requestCode, Result resultCode, Android.Content.Intent data) &lt;0xdd295de8 + 0x00a64> in :0 </p>
  
  <p>02-20 16:32:33.846  7348  7348 I MonoDroid:   at Android.App.Activity.n_OnActivityResult_IILandroid_content_Intent_ (IntPtr jnienv, IntPtr native__this, Int32 requestCode, Int32 native_resultCode, IntPtr native_data) &lt;0xdd295c80 + 0x00083> in :0 </p>
  
  <p>02-20 16:32:33.846  7348  7348 I MonoDroid:   at (wrapper dynamic-method) System.Object:f36adbb7-bad7-46f4-8e5c-eab3c45d9499 (intptr,intptr,int,int,intptr)</p>
  
  <p>02-20 16:32:33.862  7348  7348 W art     : JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable</p>
  
  <p>02-20 16:32:33.868  7348  7348 D AndroidRuntime: Shutting down VM</p>