开发者

Thread Blocks During Call

I have a serious problem, I'm developing an ap开发者_运维技巧plication that mesures on call time during a call; the problem presents when, with the phone on the ear, the thread that the timer has, blocks and no longer responds before taking off my ear. The next log shows the problem.

01-11 16:14:19.607 14558 14566 I Estado : postDelayed Async Service

01-11 16:14:20.607 14558 14566 I Estado : postDelayed Async Service

01-11 16:14:21.607 14558 14566 I Estado : postDelayed Async Service

01-11 16:14:22.597 14558 14566 I Estado : postDelayed Async Service

01-11 16:14:23.608 14558 14566 I Estado : postDelayed Async Service

01-11 16:14:24.017 1106 1106 D iddd : select() < 0, Probably a handled signal: Interrupted system call

01-11 16:14:24.607 14558 14566 I Estado : postDelayed Async Service

01-11 16:18:05.500 1106 1106 D iddd : select() < 0, Probably a handled signal: Interrupted system call

01-11 16:18:06.026 14558 14566 I Estado : postDelayed Async Service

01-11 16:18:06.026 14558 14566 I Estado : postDelayed Async Service

01-11 16:18:06.026 14558 14566 I Estado : postDelayed Async Service

01-11 16:18:06.026 14558 14566 I Estado : postDelayed Async Service

01-11 16:18:06.026 14558 14566 I Estado : postDelayed Async Service

01-11 16:18:06.026 14558 14566 I Estado : postDelayed Async Service

I've been trying with Services, Timers, Threads, AyncTasks and they all present the same problem.

My Code:

    @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;
 } 


Do you need to keep track all along the way? What about recording the moment the call begins, then when they put the phone to ear your thread blocks. When they are done with the call and it hangs up, they pull the phone away, your thread starts back up again and you can capture the time "now" and subtract one from the other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜