2011-07-17 63 views
0

我有一個活動,並且已經爲它綁定了服務。通過活動訪問服務方法

在onServiceConnected方法中,我有我從中直接訪問服務方法的服務對象。也就是說,我在服務中使用從onserviceconnected方法收到的對象從活動中訪問一個方法。

這會導致任何內存泄漏?或者這是訪問服務的錯誤方法?如果不對,我該如何解決?

private ServiceConnection mConnection = new ServiceConnection() { 

      public void onServiceConnected(ComponentName className, IBinder service) { 
       mBoundService = ((RadioPlayerService.RadioBinder)service).getService();    
       mBoundService.StartStream(mMessenger);    
      } 

      public void onServiceDisconnected(ComponentName className) { 

       mBoundService = null; 

      } 
     }; 

回答

0

看起來正確!

只要你不試圖訪問服務,當它沒有綁定(或當它不是null,在這種情況下)它會正常工作。