Application is restarting while clicking on menu item

51 Views Asked by At

I am using contact picker to chose a phone number from phone.But after using the contact picker once I click on any other button or menu, the app gets restarted. Below is my code :- Here mobilText is the textbox where I am setting the phone number which I get from contact picker.

contact.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
          startActivityForResult(i, 1);                           
    }
  });

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1 && resultCode == RESULT_OK) {
            Uri contactUri = data.getData();  

            Cursor cursor = getContentResolver().query(contactUri, null, null, null, null);
            cursor.moveToFirst();            
            String cNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));     
            mobilText.setText(cNumber+"");  
        }
    } 
0

There are 0 best solutions below