android联系人批量删除优化时间

来源:互联网 发布:对虚拟网络的看法 编辑:程序博客网 时间:2024/06/05 09:29

android联系人批量删除时总要求效率要高,时间要快。可以对联系人分块删除。以下代码,看看有没有还需要优化的地方。

private static Object mLock = new Object();class DeleteContactsThread extends Thread{long[] mIds;String ids = "";int temp_con = 0;int divide_con = 0;public DeleteContactsThread(long[] ids){//Here we can also add wakelockmIds = ids;}public void run(){super.run();synchronized(mLock){int length = mIds.length;if(length >= 1500){divide_con = 200;}else if(length > 1000){divide_con = 100;}else if(length > 500){divide_con = 50;}else divide_con = 10;try{for(int i=0;i<length;i++){ids += mIds[i] + ",";temp_con++;if(temp_con == divide_con){ids +=mIds[i];getContentResolver().delete(RawContacts.CONTENT_URI,"contact_id in (" +ids + ")", null);mProgress.incrementProgressBy(divide_con);temp_con = 0;ids = "";}}if(temp_con != 0){ids +=mIds[length - 1];getContentResolver().delete(RawContacts.CONTENT_URI,"contact_id in (" +ids + ")", null);mProgress.incrementProgressBy(temp_count);}}finally{//do something.}}}}


原创粉丝点击