2011-01-17 20 views
0

私は深刻な問題があります。呼び出し中に呼び出し時間を測定するアプリケーションを開発しています。この問題は、耳の上の電話機で、タイマーが持っているスレッドをブロックし、耳を離す前に応答しなくなったときに表示されます。次のログに問題が表示されます。呼び出し中のスレッドブロック

01-11 16:14:19.607 14558 14566 Iエスタード:postDelayed非同期サービス

01-11 16:14:20.607 14558 14566 Iエスタード:postDelayed非同期サービス

01-11午前16時14 :21.607 14558 14566 Iエスタード:postDelayed非同期サービス

01-11 16:14:22.597 14558 14566 Iエスタード:postDelayed非同期サービス

01-11 16:14:23.608 14558 14566 Iエスタード:postDelayed非同期サービス

1月11日16:14:24.017 1106 1106 DのIDDD:中断システムコール

1月11日16:14:24.607 14558 14566 Iエスタード:postDelayed非同期サービス)(< 0、おそらく扱う信号を選択します

1月11日16:18:05.500 1106 1106 DはIDDD:(選択)< 0、おそらく扱う信号:中断システムコール

1月11日16:18:06.026 14558 14566 Iエスタード:postDelayed非同期をサービス

01-11 16:18:06.026 14558 14566 Iエスタド:postDela YED非同期サービス

01-11 16:18:06.026 14558 14566 Iエスタード:postDelayed非同期サービス

01-11 16:18:06.026 14558 14566 Iエスタード:postDelayed非同期サービス

01-11 16:18:06.026 14558 14566 Iエスタード:postDelayed非同期サービス

01-11 16:18:06.026 14558 14566 Iエスタード:私はサービス、タイマ、スレッド、AyncTasksにしようとしてきたpostDelayed非同期サービス

それらはすべて同じ問題を提示します。

マイコード:

@Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE);  
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
      WindowManager.LayoutParams.FLAG_FULLSCREEN);   
     setContentView(R.layout.main); 
HangUpService.setMainActivity(this); 
objHangUpService = new Intent(this, HangUpService.class); 

    Runnable rAccion = new Runnable() { 
     public void run() { 
      TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
      tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); 

      objVibrator = (Vibrator) getSystemService(getApplicationContext().VIBRATOR_SERVICE); 

      final ListView lstLlamadas = (ListView) findViewById(R.id.lstFavoritos); 
      final EditText txtMinutos = (EditText) findViewById(R.id.txtMinutos); 
      final EditText txtSegundos = (EditText) findViewById(R.id.txtSegundos); 

     ArrayList<Contacto> cContactos = new ArrayList<Contacto>(); 
      ContactoAdapter caContactos = new ContactoAdapter(HangUp.this, R.layout.row,cContactos); 

      Cursor curContactos = getContentResolver().query(
      ContactsContract.Contacts.CONTENT_URI, 
      null, 
      null, 
      null, 
      ContactsContract.Contacts.TIMES_CONTACTED + " DESC"); 

      while (curContactos.moveToNext()){ 

     String strNombre = curContactos.getString(curContactos.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
     String strID = curContactos.getString(curContactos.getColumnIndex(ContactsContract.Contacts._ID)); 
     String strHasPhone=curContactos.getString(curContactos.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)); 
     String strStarred=curContactos.getString(curContactos.getColumnIndex(ContactsContract.Contacts.STARRED)); 

      if (Integer.parseInt(strHasPhone) > 0 && Integer.parseInt(strStarred) ==1) { 

      Cursor CursorTelefono = getContentResolver().query(
        ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
        null, 
        ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = " + strID, 
        null, null); 

      while (CursorTelefono.moveToNext()) { 

      String strTipo=CursorTelefono.getString(CursorTelefono.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); 
      String strTelefono=CursorTelefono.getString(CursorTelefono.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 
      strNumero=strTelefono; 

      String args[]=new String[1];  
      args[0]=strNumero; 

      Cursor CursorCallLog = getContentResolver().query(
       android.provider.CallLog.Calls.CONTENT_URI, 
       null, 
       android.provider.CallLog.Calls.NUMBER + "=?", 
       args, 
       android.provider.CallLog.Calls.DATE+ " DESC"); 

      if (Integer.parseInt(strTipo)==2) 
      { 
       caContactos.add(
        new Contacto(
         strNombre,    
         strTelefono 
        ) 
        ); 
      } 
      } 
      CursorTelefono.close(); 
      } 
      } 
      curContactos.close(); 

      lstLlamadas.setAdapter(caContactos); 
      lstLlamadas.setOnItemClickListener(new OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView a, View v, int position, long id) { 

      Contacto mContacto=(Contacto)lstLlamadas.getItemAtPosition(position); 

      i = new Intent(HangUp.this, Llamada.class); 

      Log.i("Estado","Declaro Intent"); 
      Bundle bundle = new Bundle();  
      bundle.putString("telefono", mContacto.getTelefono()); 
      i.putExtras(bundle); 
      startActivityForResult(i,SUB_ACTIVITY_ID);     
      Log.i("Estado","Inicio Intent"); 
      blActivo=true; 

      try { 

       String strMinutos=txtMinutos.getText().toString(); 
       String strSegundos=txtSegundos.getText().toString(); 

       if(!strMinutos.equals("") && !strSegundos.equals("")){ 

       int Tiempo = (
        (Integer.parseInt(txtMinutos.getText().toString())*60) + 
        Integer.parseInt(txtSegundos.getText().toString()) 
       )* 1000; 

       handler.removeCallbacks(rVibrate); 
       cTime = System.currentTimeMillis(); 
       cTime=cTime+Tiempo; 

       objHangUpAsync = new HangUpAsync(cTime,objVibrator,objPowerManager,objKeyguardLock); 
       objHangUpAsync.execute(); 

       objPowerManager.userActivity(Tiempo+3000, true); 
       objHangUpService.putExtra("cTime", cTime); 
    //startService(objHangUpService); 


      } catch (Exception e) { 
      e.printStackTrace(); 
      } finally { 

      } 
      } 
      }); 
     } 
    }; 
    }   

AsyncTask:

@Override 
protected String doInBackground(String... arg0) { 

    blActivo = true; 

    mWakeLock = objPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag"); 
    objKeyguardLock.disableKeyguard(); 
    Log.i("Estado", "Entro a doInBackground"); 

    timer.scheduleAtFixedRate( 
    new TimerTask() { 
    public void run() { 
    if (blActivo){ 
    if (cTime<System.currentTimeMillis()){ 

     blActivo=false; 
     objVibrator.vibrate(1000); 
     Log.i("Estado","Vibrar desde Async"); 
     this.cancel(); 

    }else{ 
     try{ 
     mWakeLock.acquire();     
     mWakeLock.release(); 
Log.i("Estado","postDelayed Async Service"); 
     }catch(Exception e){ 
     Log.i("Estado","Error: " + e.getMessage()); 
     } 
    } 
    } 
    } 
    }, 0, INTERVAL); 
    return null; 
} 

答えて

0

はあなたがすべての道に沿って追跡を維持する必要がありますか?コールが開始された瞬間を記録してから、電話機をスレッドブロックに置くとどうなりますか?コールが終了して電話が切れると、電話機が外されてスレッドが再び起動し、「今」の時間をキャプチャしてもう一方を減算することができます。

関連する問題