title: What is the best way to get distinct contacts in Android
body: <p>I am successfully storing contacts in parse.com dashboard data browser by this code.</p>
  
  <pre><code>public void readContacts(){
           ContentResolver cr = getContentResolver();
           Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
  
           if (cur.getCount() &gt; 0) {
              while (cur.moveToNext()) {
                  String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                  String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                  if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) ==1) {
                      System.out.println(name );
                      ParseObject testObject = new ParseObject("Contacts");
  
                      testObject.put("names", name);
  
                      // get the phone number
                      Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
                                             ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                                             new String[]{id}, null);
                      while (pCur.moveToNext()) {
                            String phone = pCur.getString(
                                   pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                           System.out.println( phone);
                          testObject.put("phonenumber", phone);
  
                      }
                      pCur.close();
                      testObject.saveInBackground();
             }
          }
       }
    }
  </code></pre>
  
  <p>But there is no check for the duplicate contacts !</p>
  
  <p>It stores all the contacts duplicate from sim / phone memory.</p>
  
  <p>How can it be avoided ?</p>
  
  <p><em>One possible method I think is to store distinct names(contact) in local database, &amp; then retrieving that data to store it in parse.com</em></p>
  
  <p>Is there exists a better way ?</p>
  
  <p>Thanks in advance...</p>