Android 同步和互斥
有两个android应用程序:Android 同步和互斥,android,synchronization,location,ipc,mutex,Android,Synchronization,Location,Ipc,Mutex,有两个android应用程序:App1带有Process1和Service1,App2带有Process2和Service2 还有一个应用程序AppManager,它只是一个名为ManagerService的独立服务管理服务主要做两件事: 注册侦听器以使用手机上的传感器 在这些侦听器的帮助下获取数据。注意:获取数据可能需要一些时间 现在,使用已定义的AIDL,我可以将Service1与ManagerService绑定,并将Service2与ManagerService绑定。Service1和Se
App1
带有Process1
和Service1
,App2
带有Process2
和Service2
还有一个应用程序AppManager
,它只是一个名为ManagerService
的独立服务<代码>管理服务主要做两件事:
Service1
与ManagerService
绑定,并将Service2
与ManagerService
绑定。Service1
和Service2
现在都可以调用远程方法A(…)
来请求在ManagerService
中定义的注册侦听器,然后从ManagerService
获取保存在列表中的共享传感器数据
如果现在Service1
正在执行远程方法A(…)
,以从ManagerService
获取传感器数据,例如:
List A(...) {
// ...
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
0, 0, locationListener);
// ...
return list;
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
SaveLocationToList(location);
}
}
如何确切地保证
Service2
仅在Service1
完成上述“请求注册更新列表获取列表”过程后才会请求获取传感器数据?这似乎过于复杂。为什么这三个独立的应用程序如此相互依赖?大家好,谢谢你们为我编辑和格式化这篇文章…:D我已经在这里发布了我的方式。
List A(...)
{
// ...
synchronized(this)
{
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
0, 0, locationListener);
// ...
return list;
}
}