我必須在退出時更新
geoFence
。爲此,我需要當前的位置。獲取Geofence上的當前位置.GEOFENCE_TRANSITION_EXIT
當我的應用程序被關閉我沒有偵聽onLocationChanged
。並且爲了 更新geoFence我需要我的位置。是他們的任何方式MainActivity
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
int resultCode = bundle.getInt("done");
if (resultCode == 1) {
if(!MainActivity.isGeoFenceAdded){
updateGeoFencesOnCurrentExit();//I need current location here
}
}
}
}
};
每一件事做工精細,以獲得當前位置在Geofence.GEOFENCE_TRANSITION_EXIT
public void broadcastUpdateGeoFences() {
MainActivity.isGeoFenceAdded = false;//It tells to update geoFence
Intent intent = new Intent(Constants.RECEIVER_GEOFENCE);
intent.putExtra("done", 1);
sendBroadcast(intent);
}
廣播接收器。但是當應用程序關閉時,無法找到在退出時通過currentLocation的方法。
private void updateGeoFencesOnCurrentExit(Location currentLocation){
locationHandler.updateGeoFences(currentLocation);
}
您是否在使用Intent服務? – mechdon
是的,我知道它應該是廣播接收器 – Nepster
您的實際添加地理位置請求在哪裏? –