我有一个后台服务,它使用PendingIntent
在后台跟踪设备位置运行。
服务调用mFusedLocationClient.requestLocationUpdates(mLocationRequest, locationRequest, pendingIntent
)来启动位置跟踪,但有时还会更新位置跟踪(更改更新的频率)。
是将GoogleApiClient
实例存储在服务类中,还是每次需要时都连接到它?
GoogleApiClient
会自动尝试重新连接自己。GoogleApiClient
,代码都会增加一些复杂性,因为使用connect()
建立的连接是异步的。根据你的经验,你认为什么是最好的?
发布于 2017-07-08 00:05:08
您应该在活动的googleApiClient.connect()
中调用onStart()
,在onStop()
中调用googleApiClient.disconnect()
。您可以实现GoogleApiClient.ConnectionCallbacks
,这将让您知道客户机是否通过调用public void onConnected(Bundle bundle)
成功地连接,然后您可以访问您的api。
https://stackoverflow.com/questions/44983776
复制相似问题