我有幾個Android Service
,我想綁定在我的Activity
,所以我可以監視用戶的幾個動作。是否需要爲每個服務綁定一個ServiceConnection?
爲了能夠綁定每個服務,並且我將有幾個,我需要幾個私人的ServiceConnection
s在我的活動如下?
/** Defines callbacks for service binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
GPSLocalBinder gpsBinder = (GPSLocalBinder) service;
PhotoLocalBinder photoBinder = (PhotoLocalBinder) service;
gpsService = gpsBinder.getService();
photoService = photoBinder.getService();
mGpsBound = true;
mPhotoBound = true;
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
mGpsBound = false;
mPhotoBound = false;
}
};
或者我需要在我的活動和服務之間提供更好的使用和理解有界服務的經理類嗎?
Thx爲您在這個問題上的啓示。 – JoaoFilipeClementeMartins