title: How to get last inserted contact number from the phone book android?
body: <p>How can i fetch the last inserted contact number from the android phone book. I already done with the fetching all the unique contact numbers and its count from the database and i have also made a ContentObserver for listening the updates related to phone book.but now i want last inserted contact number. I am putting my whole code over here.</p>
  
  <p>This is my code to fetch all the contacts :-</p>
  
  <pre><code>Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
              while (phones.moveToNext()) {
                  phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                  listNumbers.add(phoneNumber);
              }
  
              ArrayList&lt;String&gt; unique = removeDuplicates(listNumbers);
              for (String element : unique) {
                  System.out.println(element);
              }
  
              sb = new StringBuffer();
              for (String item : unique) {
                  if (sb.length() &gt; 0) {
                      sb.append(',');
                  }
                  sb.append(item);
              }
              numbersString = sb.toString();
          //  Log.e("BUFFER", numbersString.toString());
              phones.close();
              Log.e("SIZE", unique.size() + "");
  </code></pre>
  
  <p>And Now this is the code for contentobserver :-</p>
  
  <pre><code>private ContentObserver mObserver = new ContentObserver(new Handler()) {
  
      @Override
      public void onChange(boolean selfChange) {
          super.onChange(selfChange);
  
          final int currentCount = getContactCount();
          if (currentCount &lt; mContactCount) {
              // DELETE HAPPEN.
              Log.e("STATUS===&gt;", "Deletion");
          } else if (currentCount == mContactCount) {
              // UPDATE HAPPEN.
          } else {
              // INSERT HAPPEN.
              Log.e("STATUS===&gt;", "Insertion");
  
  
          }
          mContactCount = currentCount;
      }
  };
  </code></pre>
  
  <p>In onchange INSERT Condition i want that newly added contact number.</p>