title: Fetch contact list along with their primary email and phone number in a single query from the ContactProvider
body: <p>I am trying to get the list of contacts with their phone and email details to display them in a list. What i have done now is do three separate queries. </p>
  
  <ol>
  <li>Get list of contacts to contactCursor from Contacts.CONTENT_URI</li>
  <li>Get all phone numbers to phoneCursor from Phone.CONTENT_ITEM_TYPE</li>
  <li>Get all emails to emailCursor from Email.CONTENT_ITEM_TYPE</li>
  </ol>
  
  <p>Then i will am Looping through the contactCursor. For every contact, i will loop through the phoneCursor and emailCursor to get the primary phone number and email. But this takes some time to load and is clearly visible when the number of contacts is large. Is there any way that i can get all these details in the first step itself.</p>
  
  <p>Below is the code snippet:</p>
  
  <pre><code>    Cursor contacts = resolver.query(Contacts.CONTENT_URI, 
              CONTACT_PROJECTION, Contacts.HAS_PHONE_NUMBER + " != 0", null, Contacts._ID + " ASC");
      Cursor phone = resolver.query(Data.CONTENT_URI, PHONE_PROJECTION, 
              Data.MIMETYPE + "=? ", 
              new String[]{Phone.CONTENT_ITEM_TYPE}, 
              Data.CONTACT_ID + " ASC");
  
      Cursor email = resolver.query(Data.CONTENT_URI, EMAIL_PROJECTION, 
              Data.MIMETYPE + "=? ", 
              new String[]{Email.CONTENT_ITEM_TYPE}, 
              Data.CONTACT_ID + " ASC");
  
      if (contacts!=null &amp;&amp; contacts.moveToFirst()) {
          do {
  
              String contactId = contacts.getString(0);
  
              if(phone!=null &amp;&amp; phone.moveToFirst()){
                  do{
                      if(contactId.equalsIgnoreCase(phone.getString(0))){
                          contact.setMobile(phone.getString(1));
  
                          break;
                      }
                  }while(phone.moveToNext());
              }
  
              if(email!=null &amp;&amp; email.moveToFirst()){
                  do{
                      if(contactId.equalsIgnoreCase(email.getString(2))){
                          contact.setEmailWork(email.getString(1));
                          break;
                      }
                  }while(email.moveToNext());
              }
  
  
  
          } while (contacts.moveToNext());
  </code></pre>