Reading address book learning notes and android learning notes in android

Source: Internet
Author: User

Reading address book learning notes and android learning notes in android

1. When reading the address book at a time, try to read as few attributes as possible, especially when the list is displayed, it will make the loading speed of your list unbearable. We recommend that you load a few attributes first, then, all attributes are loaded at the time of details.

2. When reading a type of attribute, we recommend that you use a cursor and place it outside the loop to accelerate the speed. projection is used to indicate the columns to be queried, CONTACTOR_ION in the following code ).

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(ContactsContract.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();phoneString = phones.getString(phoneIndex);displayNameString = phones.getString(displayNameIndex);contactIdString = phones.getString(contactIdIndex);}}} catch (Exception e) {Log.e(TAG, e.getMessage());} finally {if (phones != null)phones.close();}

3. Check whether the DEPARTMENT attribute of a contact is ORGANIZATION. TITLE, rather than ORGANZITION. DEPARTMENT. This is a pitfall.



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.