As shown in the Code, the speed of 2 is several times faster.
Public void getcontact (context con ){
Cursor cursor = con. getcontentresolver (). Query (contactscontract. Contacts. content_uri,
Projection, null, null, query_order_by_name );
If (cursor! = NULL ){
Try {
List <ucontact> ucontacts = new arraylist <ucontact> ();
If (cursor. movetofirst ()){
Do {
Ucontact item = new ucontact ();
Item. setid (cursor. getlong (0 ));
Item. setphotoid (cursor. getlong (1 ));
Item. setname (cursor. getstring (2 ));
Item. setfirstchar (getfirstchar (cursor
. Getstring (Android. OS. Build. version. sdk_int> = 8? 3
: 2 )));
If (Android. OS. Build. version. sdk_int> = 8)
Item. setsortkey (cursor. getstring (3 ));
Queryumgroupbyid (con, item, item. GETID ());
Ucontacts. Add (item );
} While (cursor. movetonext ());
}
Collections. Sort (ucontacts, new arraycompare ());
Iscontactchange = false;
// Mcontactcount. Put (0, ucontacts. Size ());
} Catch (exception e ){
E. printstacktrace ();
} Finally {
Cursor. Close ();
Cursor = NULL;
}
}
}
Private void queryumgroupbyid (context con, ucontact contact, long ID ){
Int groupid = 0;
Cursor cursor = con. getcontentresolver (). Query (contactscontract. Data. content_uri, new string [] {commondatakinds. groupmembership. group_row_id}
, Data. contact_id + "=? And "+ data. mimetype +" =? ",
New String [] {string. valueof (ID), um_group_mimetype}, null );
If (cursor! = NULL ){
Int COUNT = cursor. getcount ();
If (count> 0 ){
Cursor. movetofirst ();
Groupid = cursor. getint (0 );
Contact. setumgroupid (groupid );
If (cursor! = NULL ){
Cursor. Close ();
Cursor = NULL;
}
}
}
}
Public void getcontact2 (context con ){
Cursor cursor_group = con. getcontentresolver (). Query (contactscontract. Data. content_uri,
New String [] {data. contact_id, commondatakinds. groupmembership. group_row_id}
, Data. mimetype + "=? ",
New String [] {um_group_mimetype}, null );
If (cursor_group! = NULL ){
Mgroupmap. Clear ();
Int COUNT = cursor_group.getcount ();
If (count> 0 ){
Cursor_group.movetofirst ();
For (INT I = 0; I <count; I ++ ){
Int contactid = cursor_group.getint (0 );
Int groupid = cursor_group.getint (1 );
Mgroupmap. Put (contactid, groupid );
Cursor_group.movetonext ();
}
If (cursor_group! = NULL ){
Cursor_group.close ();
Cursor_group = NULL;
}
}
}
Cursor cursor = con. getcontentresolver (). Query (contactscontract. Contacts. content_uri, projection, null, null, query_order_by_name );
If (cursor! = NULL ){
Try {
List <ucontact> ucontacts = new arraylist <ucontact> ();
If (cursor. movetofirst ()){
Do {
Ucontact item = new ucontact ();
Item. setid (cursor. getlong (0 ));
Item. setphotoid (cursor. getlong (1 ));
Item. setname (cursor. getstring (2 ));
Item. setfirstchar (getfirstchar (cursor
. Getstring (Android. OS. Build. version. sdk_int> = 8? 3
: 2 )));
If (Android. OS. Build. version. sdk_int> = 8)
Item. setsortkey (cursor. getstring (3 ));
Item. setumgroupid (mgroupmap. Get (item. GETID ()));
Ucontacts. Add (item );
} While (cursor. movetonext ());
}
Collections. Sort (ucontacts, new arraycompare ());
Iscontactchange = false;
// Mcontactcount. Put (0, ucontacts. Size ());
} Catch (exception e ){
E. printstacktrace ();
} Finally {
Cursor. Close ();
Cursor = NULL;
}
}
}