I'm wondering why my code takes so long to open. It takes a good 2-4 seconds on my android device (LG G4) in order to open this fragment. I have a phone contact class with these variables I want to retrieve in them.

```
    public class PhoneContact {
    public String contact_name = "";
    public String contact_number = "";
    public int contact_id = 0;
}

```

In order to inflate these contacts I have a listview fragment that displays these data. I display the fragment by doing this:

```
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle SavedInstanceState){
    myFragmentView = inflater.inflate(R.layout.fragment_phonecontacts, container, false);
    getPhoneContact();
    return myFragmentView;
}

```

Finally in order to retrieve my phone contacts information I did this:

```
public void getPhoneContact() {
    ArrayList<PhoneContact> phoneContacts = new ArrayList<PhoneContact>();
    Cursor cursor = null;
    ContentResolver contentResolver = getActivity().getContentResolver();

    try {
        cursor = contentResolver.query(
                ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    } catch (Exception e) {
        Log.e("Error on contact list", e.getMessage());
    }

    if (cursor.getCount() > 0) {
        while (cursor.moveToNext()) { 
            PhoneContact phoneContact = new PhoneContact();
            String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
            String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            phoneContact.contact_name = name;

            int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)));
            if (hasPhoneNumber > 0) {

                Cursor phoneCursor = contentResolver.query(
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI
                        , null
                        , ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?"
                        , new String[]{id}
                        , null);

                while (phoneCursor.moveToNext()){
                    String number = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    phoneContact.contact_number = number;
                }
                phoneCursor.close();
            }
            phoneContacts.add(phoneContact);
        }
        PhoneContactsAdapter adapter = new PhoneContactsAdapter(this.getContext(), phoneContacts);
        ListView listView = (ListView) myFragmentView.findViewById(R.id.listview_phoneContacts);
        listView.setAdapter(adapter);
    }
}

```

Checked if the cursor is able to traverse through the contact database.
If it is then go through each contact and grab their ID, name, phone number.
Once there are no more contacts to search for I close the cursor and then make the phone contact. The home contact gets added to the array and then binds to the list view through an adapter.

Does anyone have any suggestions on how to speed this up or another way to retrieve my phone contacts.