Note that there are some explanatory texts on larger screens.

plurals
  1. POBack Press Force Close
    primarykey
    data
    text
    <ul> <li>I have Used Pick Contacts functionality in my Activity.Its working fine to pick contact and other details info like Name.</li> <li>But when i click button it goes for contact intent and shows number all is well. </li> <li>But if i didn't select number and clicking back press means the app getting force close.</li> </ul> <p><strong>Code</strong></p> <pre><code>Intent inten = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(inten,PICK_CONTACT); @Override public void onActivityResult(int reqCode, int resultCode, Intent data) { super.onActivityResult(reqCode, resultCode, data); Cursor c; switch (reqCode) { case (PICK_CONTACT): Uri result = data.getData(); Log.v("TAG", "Got a result: " + result.toString()); // get the contact id from the Uri String id = result.getLastPathSegment(); // query for phone numbers for the selected contact id c = getContentResolver().query( Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[]{id}, null); int phoneIdx = c.getColumnIndex(Phone.NUMBER); int phoneType = c.getColumnIndex(Phone.TYPE); if(c.getCount() &gt; 1) { // contact has multiple phone numbers final CharSequence[] numbers = new CharSequence[c.getCount()]; int i=0; if(c.moveToFirst()) { while(!c.isAfterLast()) { // for each phone number, add it to the numbers array String type = (String) Phone.getTypeLabel(this.getResources(), c.getInt(phoneType), ""); // insert a type string in front of the number String number = type + ": " + c.getString(phoneIdx); numbers[i++] = number; c.moveToNext(); } // build and show a simple dialog that allows the user to select a number AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Select Number"); builder.setItems(numbers, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { String number = (String) numbers[item]; int index = number.indexOf(":"); number = number.substring(index + 2); cNumber=number; edt.setText(cNumber); //Toast.makeText(getApplicationContext(), number, Toast.LENGTH_LONG).show(); // loadContactInfo(number); // do something with the selected number } }); AlertDialog alert = builder.create(); alert.setOwnerActivity(this); alert.show(); } else Log.w("TAG", "No results"); } else if(c.getCount() == 1) { // contact has a single phone number, so there's no need to display a second dialog if(c.moveToFirst()) { cNumber = c.getString(c.getColumnIndex("data1")); edt.setText(cNumber); //Toast.makeText(getApplicationContext(), cNumber, Toast.LENGTH_LONG).show(); } } break; } } </code></pre> <p>In my activity i have written back press also...</p> <pre><code>@Override public void onBackPressed() { btnflag++; if(btnflag==1) { Intent mainscr = new Intent(FindList1.this, MainScreen.class); startActivity(mainscr); btnflag=0; finish(); } } </code></pre> <p>But Unfortunately the crash has happened.....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload