Android loading contacts is too slow

后端 未结 2 1552
遥遥无期
遥遥无期 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:06

    Your Spinners would populate a lot faster if you used a break to jump out of your for-loop once you assign

    num = i
    
    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题