how to handle the null cursor when the user click back or cancel inside the contact list?
<p>When the user is in the contact list, he/she is supposed to select a person from the contact list and the contact activity will closed and call the onActivityResult();
But when i clicked on the back button or cancel button on the upper corner of the contact page, the cursor will will null and there is a null pointer exception. 
And idea?</p>

<p>code:</p>

<pre><code>selectContactButton.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                Intent intent = new Intent(Intent.ACTION_PICK);
                 intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
                 startActivityForResult(intent, PICK_CONTACT);
            }
        });


public void onActivityResult(int requestCode, int resultCode, Intent intent) 
    {

      if (requestCode == PICK_CONTACT)   //I tried to do if intent!=null then run this codes but there is the same error
      {         

          Cursor cursor =  managedQuery(intent.getData(), null, null, null, null);
          cursor.moveToNext();

           String  name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); 

          editName.setText(name); //edittext view

      }

    }
</code></pre>
