android.i의 장치에서 모든 전화 연락처를 가져 오려면 다음 code.but를 사용했지만 결과를 반환하는 데 더 많은 시간이 필요합니다. 해결책이 있습니까?안드로이드의 연락처
ContentResolver cr = getContentResolver();
int index=0;
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0)
{
phoneNames=new String[cur.getCount()];
phoneNumbers=new String[cur.getCount()];
while (cur.moveToNext())
{
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
name = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
{
phoneNames[index]=name;
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
while (pCur.moveToNext())
{
phoneIndex++;
phoneNumbers[index] = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
index++;
}
pCur.close();
}
}
이 코드를 실행하는 데 많은 시간이 필요합니까? – Dalmas
yes.some 6 초 .. – Kakey
n^2 개의 다른 데이터베이스 트랜잭션에서 n^3 복잡성이 있습니다. 거의 모든 데이터베이스를 단일 데이터베이스 쿼리로 처리 할 수 있습니다. – Falmarri