0
我正在Android中实现需要访问Location对象的应用程序。 我在对象中运行此对象的所有后勤。Android - 服务变量访问
然后我绑定我的活动到该服务,ServiceGPS.java,服务和位置更新似乎工作正常,但问题是,我不能访问ServiceGPS内的位置对象。
到服务的连接被定义为我在Activity类
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
@SuppressWarnings("unchecked")
ServiceGPS mService = ((LocalBinder<ServiceGPS>)service).getService();
// Get hold of your resource, db etc and pass it through to a object that will use it
mLocationManager = mService.getmLocation();
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
// TODO Auto-generated method stub
}
};
如果我调试代码,mLocationManager recibes正确的值更新一个全局变量。但我想在我的活动中访问mService.getmLocation(),但我不能。
因为我不能声明mService作为类成员。
有什么建议吗?
非常感谢您的无价帮助。
BR, David。