有沒有更快的方法來讀取android中的聯繫人?例如,我用光標的方法需要3-5秒才能讀取30-50個聯繫人。這很長。快速閱讀聯繫人android
Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext())
{
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.equalsIgnoreCase("1"))
hasPhone = "true";
else
hasPhone = "false" ;
if (Boolean.parseBoolean(hasPhone))
{
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
while (phones.moveToNext())
{
names.add(cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)));
numbers.add(phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
}
phones.close();
}
}
任何想法?
我這個答案達成一致。此外,你應該使用[CursorLoader](http://developer.android.com/reference/android/content/CursorLoader.html),因爲它將完成UI線程的工作(如果你還沒有這樣做的話)。 – hwrdprkns 2012-04-20 17:32:06
是的,你可以做到這一點... :) – Kri 2012-04-20 17:35:10