2012-09-19 2 views
1

내 장치에 3000 자 이상이 있습니다. 데이터베이스의 모든 메시지를 읽으려고합니다. 나는이 쿼리를 사용하고 있습니다 :데이터베이스에서 SMS 레코드 읽기 android

Cursor cur1 = c.getContentResolver().query(Uri.parse("content://sms/"), null, null, null, null); 

cur1.getCount()이 반환 모든 3000 SMS를,하지만 난 루프를 통해 해석 할 때에 만

을 인쇄 로그 캣 (400)

Cursor cur1 = c.getContentResolver().query(Uri.parse("content://sms/"), null, null, null, null); 
int size = cur1.getCount(); 

if(size > 0) 
{ 
    sms = new SMS[size]; 
    //int i = 0; 
    for(int i = 0 ; i < size ; i++) 
    { 
     cur1.moveToNext(); 
     ContactInfo p = new ContactInfo(); 
     String content = cur1.getString(cur1.getColumnIndex("body")); 
     String number = cur1.getString(cur1.getColumnIndex("address")); 
     long date = cur1.getLong(cur1.getColumnIndex("date")); 
     String person = cur1.getString(cur1.getColumnIndex("person")); 
     String protocol = cur1.getString(cur1.getColumnIndex("protocol")); 
     String name = p.getName(number, c); 
     String type = null; 

     Calendar cal=Calendar.getInstance(); 
     cal.clear(); 
     cal.setTimeInMillis(date); 

     String date_time=String.format("%1$te %1$tB %1$tY,%1$tI:%1$tM:%1$tS %1$Tp",cal); 

     Log.i("INFO", content+" "+i); 

     sms[i] = new SMS(type , name , number , date_time , content); 
    } 
} 

500 후 400 ~ 500 반복을 통해 실행

09-19 20:28:31.148: E/liblog(3153): failed to call dumpstate 
09-19 20:28:31.179: I/ActivityManager(3153): Process com.arslan (pid 1766) has died. 
+0

예외가 발생합니까? – Fildor

+1

그래서 for 루프에서 처음 400-500 회 반복 한 후에 어떻게됩니까? –

+0

루프가 너무 일찍 종료되는 이유가 없습니다. logcat에 아무것도 나타나지 않습니까? – Turnsole

답변

0

많은 다른 프로세스 장치와 그것으로 인해 공정 살해 이유 연속 CPU 시간이 많이 걸립니다 읽기 3000 메시지의 긴 과정을 실행하고 있습니다. 내가 스레드를 통해 그것을 읽으려고했을 때 잘 동작합니다.

final Cursor cur1 = c.getContentResolver().query(Uri.parse("content://sms/"), null, null, null, "date ASC"); 
    final int size = cur1.getCount(); 

    final int sleeptimer = size; 

    final SMS [] sms = new SMS[size]; 


    Thread myThread = new Thread() 
    { 
     public void run() 
     { 
      try 
      { 
       int currentwait = 0; 
       int j=0; 
       while(currentwait < sleeptimer) 
       { 
        sleep(200); 
        currentwait+=200; 
        for(int i = 0 ; i < 200 ; i++) 
        { 
         if(!cur1.moveToNext()) 
         { 
          break; 
         } 
         ContactInfo p = new ContactInfo(); 
         String content = cur1.getString(cur1.getColumnIndex("body")); 
         String number = cur1.getString(cur1.getColumnIndex("address")); 
         long date = cur1.getLong(cur1.getColumnIndex("date")); 
         String protocol = cur1.getString(cur1.getColumnIndex("protocol")); 
         String name = p.getName(number, c); 
         String type = null; 

         Calendar cal=Calendar.getInstance(); 
         cal.clear(); 
         cal.setTimeInMillis(date); 

         String date_time=String.format("%1$te %1$tB %1$tY,%1$tI:%1$tM:%1$tS %1$Tp",cal); 

         Log.i("INFO", content+" "+j); 

         sms[j] = new SMS(type , name , number , date_time , content); 
         j++; 
        } 
       } 
      } 
      catch(Exception e) 
      { 

      } 
      finally{ 

      } 
     } 
    }; 
    myThread.start(); 
관련 문제