3
在我看來,在Android上訪問聯繫人非常緩慢,並且不必要地涉及遊標。它如何加速?如何加速訪問Android上的聯繫人?
在我看來,在Android上訪問聯繫人非常緩慢,並且不必要地涉及遊標。它如何加速?如何加速訪問Android上的聯繫人?
1.當您第一次閱讀聯繫人時,可能會減少某些屬性。
2.閱讀屬性類型時,可以使用遊標。
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()) {
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();
}
linkManForm是什麼? –
@SomeGuy哦,它是一個用來保存LinkMan信息的對象,我將編輯我的代碼並刪除這一行。 – Scavenger