私の活動時にすべてのアクティブジオフェンスを削除しようとしています。ここで活動中のすべてのアクティブジオフェンスを削除します。
は、私が使用していますコードです:
private PendingIntent getGeofencePendingIntent() {
Intent intent = new Intent(this, GeofenceService.class);
// We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling addgeoFences()
return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
//Setup permissions for location.
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
},
LOCATION_PERMISSION_CODE
);
} else {
if (lm != null)
lm.removeUpdates(this);
}
if (allRequestIds.size() != 0) {
LocationServices.GeofencingApi.removeGeofences(
mGoogleApiClient,
allRequestIds
);
allRequestIds.clear();
filterMap.clear();
registeredFences.clear();
mGoogleApiClient.disconnect();
}
}
私も試してみました:
if (allRequestIds.size() != 0) {
LocationServices.GeofencingApi.removeGeofences(
mGoogleApiClient,
getGeofencePendingIntent()
);
allRequestIds.clear();
filterMap.clear();
registeredFences.clear();
mGoogleApiClient.disconnect();
}
私はこのエラーを取得しています:
Unable to destroy activity, GoogleApiClient is not connected yet.
私ならば、同じことが起こっていますonStop()メソッドで行います。
最終的には、前回実行時に追加されたジオフェンスが保持されます。私はそれを望んでいない。何がうまくいかないのですか?