Журналы вызовов медленно загружаются

Привет, Я разрабатываю приложение для Android, где я пытаюсь отобразить журналы вызовов в виде списка.

private void getCallDetails() 
{
 Cursor managedCursor = getContentResolver().query( CallLog.Calls.CONTENT_URI,null, null,null, "date DESC");

 int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER ); 
 int type = managedCursor.getColumnIndex( CallLog.Calls.TYPE );
 int date = managedCursor.getColumnIndex( CallLog.Calls.DATE);
 int duration = managedCursor.getColumnIndex( CallLog.Calls.DURATION);
 int nameid = managedCursor.getColumnIndex( CallLog.Calls.CACHED_NAME);

 while (managedCursor.moveToNext())
 {
 HashMap<string, string=""> map = new HashMap<string, string="">();
 phNumber = managedCursor.getString( number );
 //type of call
 String callType = managedCursor.getString( type );

 //call date
 String callDate = managedCursor.getString( date );
 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM");
 String dateString = formatter.format(new Date(Long.valueOf(callDate)));

 //call time
 SimpleDateFormat time = new SimpleDateFormat("HH:mm");
 String timeString = time.format(new Date(Long.valueOf(callDate)));

 String calldur = managedCursor.getString(duration);
 int sec = Integer.parseInt(calldur);

 //converting seconds 
 String dur = String.format("%02d:%02d:%02d", sec/3600, (sec%3600)/60, (sec%60));

 String name = managedCursor.getString(nameid);
 if(name == null)
 {
 map.put(contactName, "Unknown");
 }
 else
 {
 map.put(contactName, name); 
 }

 int dir = 0;
 int imageId = 0;
 int dircode = Integer.parseInt( callType );
 switch( dircode )
 {
 case CallLog.Calls.OUTGOING_TYPE:
 dir = R.drawable.outgoing;
 imageId = R.drawable.clock;
 callDuration = dur;
 break;

 case CallLog.Calls.INCOMING_TYPE:
 dir = R.drawable.incoming;
 imageId = R.drawable.clock;
 callDuration = dur;
 break;

 case CallLog.Calls.MISSED_TYPE:
 dir = R.drawable.missed;
 callDuration = " ";
 imageId = R.drawable.empty;
 break;
 }
 map.put(phone, phNumber);
 map.put(DateOfCall,dateString ); 
 map.put(TimeOfCall,timeString ); 
 dirType = String.valueOf(dir);
 map.put(typeofCall,dirType );
 map.put(durationOfCall, callDuration);

 clkimgId = String.valueOf(imageId);
 map.put(imgId,clkimgId);
 map.put(image,contactID);

 DetailsList.add(map);
 }

 managedCursor.close(); 
}
</string,></string,>

Я вызываю вышеуказанный getCallDetails() в doInBackground и загружаю адаптер в onPostExecute как

adapter = new Adapter(Cal.this, DetailsList); 
 callList.setAdapter(adapter);

Но эта загрузка слишком медленная. Как я могу это исправить? Не знаю, где я ошибаюсь.

Пожалуйста помоги. Благодарю!

1 ответ

открытый класс CallSmsSafeService extends Service {

private class MyPhoneListener extends PhoneStateListener{
 @Override
 public void onCallStateChanged(int state, String incomingNumber) {
 super.onCallStateChanged(state, incomingNumber);
 switch (state) {
 case TelephonyManager.CALL_STATE_RINGING:
 String mode = dao.findMode(incomingNumber);
 if("1".equals(mode)||"3".equals(mode)){
 Log.i(TAG,"这是黑名单号码,挂断电话。。。");
 //监视呼叫记录的生成,如果呼叫记录产生了。删除呼叫记录。
 Uri url = Uri.parse("content://call_log/calls");
 getContentResolver().registerContentObserver(url, true, new CallLogObserver(new Handler(), incomingNumber));

 }
 break;
 }
 }
}

private class CallLogObserver extends ContentObserver{
 private String incomingNumber;
 public CallLogObserver(Handler handler, String incomingNumber) {
 super(handler);
 this.incomingNumber = incomingNumber;
 }

 @Override
 public void onChange(boolean selfChange) {
 super.onChange(selfChange);
 getContentResolver().unregisterContentObserver(this);
 deleteCalllog(incomingNumber);
 }
}


@Override
public void onDestroy() {
 unregisterReceiver(receiver);
 receiver = null;
 tm.listen(listener, PhoneStateListener.LISTEN_NONE);
 listener = null;
 super.onDestroy();
}

/**
 * 清除呼叫记录
 * @param incomingNumber
 */
public void deleteCalllog(String incomingNumber) {
 ContentResolver resolver = getContentResolver();
 Uri url = Uri.parse("content://call_log/calls");
 resolver.delete(url, "number=?", new String[]{incomingNumber});
}

}

licensed under cc by-sa 3.0 with attribution.