Android loading contacts is too slow

后端 未结 2 1572
遥遥无期
遥遥无期 2021-01-14 05:40

in my app there are 5 spinners populated with the contacts in the phone. I am using the code below to populate an array with the contacts and then populate the spinners with

2条回答
  •  無奈伤痛
    2021-01-14 06:14

    I would say that the way you query your contacts data is wrong.

    It looks like you're fetching ALL your contacts with all the contact's data from the database, and then filtering the contacts in a while loop. I would suggest doing this from within the query, something like this (not tested):

    Cursor cur = cr.query(
        ContactsContract.Contacts.CONTENT_URI, 
        new String[] { "_ID", "DISPLAY_NAME" },
        "HAS_PHONE_NUMBER = ?", new String[] { "1" }, 
        null);
    

提交回复
热议问题