を使用するアプリがありますgps
。アプリが(ユーザーまたはAndroid OSによって)強制的に閉じられ、再度開かれない限り、正常に機能しています。gps
その後、更新を閉じることができないようです。これは私のコードです:
private void registerLocationUpdates() {
Intent intent = new Intent(ParkOGuardActivity.class.getName()
+ ".LOCATION_READY");
pendingIntent = PendingIntent.getBroadcast(
getApplicationContext(), 0, intent, 0);
// minimum every 1 minutes, 5 kilometers
this.locationManager.requestLocationUpdates(this.provider, 5000,
300000, pendingIntent);
}
private void cancelLocationUpdates() {
if(pendingIntent != null){
Log.d(TAG,pendingIntent!=null ? "pending is not null" : "pending is null");
this.locationManager.removeUpdates(pendingIntent);
}
}
メソッドを呼び出している場合は問題ありませんcancelLocationUpdates()
が、アプリを再度開いた後 (強制的に閉じた後)pendingIntent
は null であり、removeUpdates を実行できません...それを行う方法はありますか?