I use top
within a FusedLocationProviderClient
.
I would like to "stop" it in a right way.
Is it good to use following code?
Service
And the rest code
@Override
public void onDestroy() {
super.onDestroy();
// Stop Looper of FusedLocationProviderClient
if (locationClient != null) {
locationClient = null;
}
}
答案 0 :(得分:2)
只需在onDestroy
中调用removeLocationUpdates即可对于requestLocationUpdates,它说:
此调用将保持Google Play服务连接处于活动状态,因此请确保在不再需要时调用removeLocationUpdates(LocationCallback),否则您将失去自动连接管理的优势。
答案 1 :(得分:0)
只需将onDestroy();
更改为:
@Override
protected void onDestroy() {
super.onDestroy();
if(locationclient!=null)
locationclient.disconnect();
}