Application hangs when contact display
<p>I want to fetch my phone contact name,number and email in single query. Is that possible to fetch all in 1 Query?</p>

<p>I have almost 1000 contacts in my phone and its get hanged when I tried following line of code to display my contact:</p>

<pre><code>    Cursor cursor = this.getContentResolver().query(intent.getData(), null, null, null,null); 
while (cursor.moveToNext()) 
{           
    String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));          
    hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
    if ( hasPhone.equalsIgnoreCase("1"))
        hasPhone = "true";
    else
        hasPhone = "false" ;

    if (Boolean.parseBoolean(hasPhone)) 
    {
        Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, 
                ContactsContract.Contacts.DISPLAY_NAME + " COLLATE NOCASE");
        while (phones.moveToNext()) 
        {
            String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            String name = phones.getString(phones.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));                                   
        }
        phones.close();
    }
    // Find Email Addresses
    Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,
        ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,null,
        ContactsContract.Contacts.DISPLAY_NAME + " COLLATE NOCASE");// contactId+ " DESC");
    while (emails.moveToNext()) 
    {
        String emailAddress = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));             
        String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));               
    }
    emails.close(); 
    }  //while (cursor.moveToNext()) 
</code></pre>
