2010-08-17 129 views

回答

0

可以綁定,並從ServiceConnection在onServiceConnected致電您的服務的方法

+0

但是有了這個,我可以通過該服務詭計運行溝通? – Skatephone 2010-08-18 10:13:26

+0

是的,與bindService和您的ServiceCommunication對象和您的綁定 – fedj 2010-08-18 20:34:27

+0

我設法與服務交流,但現在我有一個新問題:如果我嘗試程序normaly它沒關係,但如果按紅色電話按鈕,使屏幕黑色比它沒有註冊我的傳感器的值?任何想法? – Skatephone 2010-08-21 12:07:48

0

我在我的應用程序這樣做,但我不「T設法通過變量toRec和陣營:

private ServiceConnection mConnection = new ServiceConnection() { 
     public void onServiceConnected(ComponentName className, IBinder service) { 
      mBoundService = ((SensorService.LocalBinder)service).getService(); 
      Toast.makeText(SensorsState.this, R.string.local_service_connected, 
        Toast.LENGTH_SHORT).show(); 
      mBoundService.toRec=toRec; 
      mBoundService.camp=CAMPIONI_FFT; 
     } 

     public void onServiceDisconnected(ComponentName className) { 
      mBoundService = null; 
      Toast.makeText(SensorsState.this, R.string.local_service_disconnected, 
        Toast.LENGTH_SHORT).show(); 
     } 
    }; 

    void doBindService() { 
     bindService(new Intent(SensorsState.this, 
       SensorService.class), mConnection, Context.BIND_AUTO_CREATE); 
     mIsBound = true; 
    } 

    void doUnbindService() { 
     if (mIsBound) { 
      unbindService(mConnection); 
      mIsBound = false; 
     } 
    } 
    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     doUnbindService(); 
    } 

TNK的