本文共 780 字,大约阅读时间需要 2 分钟。
我想在我的Activity中绑定几个
Android服务,所以我可以监视用户的几个动作.
为了能够绑定每个服务,我将有几个,我的活动中是否需要几个私有ServiceConnections,如下所示?
/** 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;
}
};
或者,我是否需要在我的活动和服务之间使用经理类,以便更好地使用和理解有界服务?
转载地址:http://kiima.baihongyu.com/