Android Address Book read optimization acceleration

Source: Internet
Author: User

1, when reading the address book once read, as little as possible to read all the attributes, especially when the list is displayed, will make your list loading speed becomes unbearable, it is recommended to load a small number of properties, and then load all the properties when the details.

2, when reading a class of attributes, it is recommended to use a cursor, and placed outside the loop, can significantly speed up, with projection (indicating the column to query, in the code below is Contactor_ion).

The sample code is as follows:

        private static final string[] Contactor_ion = new string[]{contactscontract.commondatakinds.phone.contact_id, Contactscontract.contacts.display_name,contactscontract.commondatakinds.phone.number};
。。。
                Cursor phones = null; Contentresolver CR = Getcontentresolver (); try {phones = Cr.query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, Contactor_ion, NULL, NULL, "Sort_key"), if (phones! = null) {final int contactidindex = Phones.getcolumnindex (contactscont Ract. CommonDataKinds.Phone.CONTACT_ID); final int displaynameindex = Phones.getcolumnindex ( ContactsContract.Contacts.DISPLAY_NAME); final int phoneindex = Phones.getcolumnindex ( ContactsContract.CommonDataKinds.Phone.NUMBER); String phonestring, Displaynamestring, Contactidstring;while (Phones.movetonext ()) {Linkmanform LinkManForm = new Linkmanform ();p honestring = phones.getstring (phoneindex);d isplaynamestring = phones.getstring (DisplayNameIndex); contactidstring = phones.getstring (Contactidindex);}}                catch (Exception e) {log.e (TAG, E.getmessage ());} finally {if (phones! = null) Phones.close ();}

3, query the contact's department attribute is organization.title, not organzition.department, this is a pit.


Android Address Book read optimization acceleration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.