Reading complete contact information in Android
Use AsyncQueryHandler, a helper class to help make handling asynchronous ContentResolver queries easier.

It basically wraps the ContentResolver object and handles background execution of its operations (CRUD) as well as passing messages (result) from the between threads (background and main/UI).

Just use to call the queryHandler.startQuery method and you will get callback in onQueryComplete method.

Example

class QueryHandler extends AsyncQueryHandler {

        public QueryHandler(ContentResolver cr) {
            super(cr);
        }

        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            switch (token) {

                case CONTACT_QUERY:
//Do your stuff here
                    if (cursor.moveToFirst()) {
                        // Iterate through the cursor
                        do {

                            String id = cursor.getString(cursor.getColumnIndex(
                                    ContactsContract.Contacts._ID));
                            Log.e(TAG, " ID " + id);

                        } while (cursor.moveToNext());
                    }
                    break;
}
}


Use below method to fetch contact and add projection, selection according to your requirment.

public void fetchContact(){
        queryHandler.startQuery(CONTACT_QUERY, null, ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    }