From 2c3f3455999866991d9a928d7b206156bee7cad7 Mon Sep 17 00:00:00 2001 From: Robin Date: Mon, 20 Dec 2021 20:14:04 +0100 Subject: [PATCH] stop route werkend --- app/src/main/java/nl/ags/picum/UI/MapActivity.java | 3 ++- app/src/main/java/nl/ags/picum/location/gps/Location.java | 7 +++++++ .../main/java/nl/ags/picum/mapManagement/MapManager.java | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nl/ags/picum/UI/MapActivity.java b/app/src/main/java/nl/ags/picum/UI/MapActivity.java index cce2725..21e4665 100644 --- a/app/src/main/java/nl/ags/picum/UI/MapActivity.java +++ b/app/src/main/java/nl/ags/picum/UI/MapActivity.java @@ -340,6 +340,7 @@ public List convertWayPointToGeoPoint(List points) { public void onFSBClicked(View view) { if (this.mapViewModel == null) return; - mapViewModel.getMapManager().stopRoute(mapViewModel.getCurrentRoute()); + new Thread(() ->{ mapViewModel.getMapManager().stopRoute(mapViewModel.getCurrentRoute());}).start(); + finish(); } } \ No newline at end of file diff --git a/app/src/main/java/nl/ags/picum/location/gps/Location.java b/app/src/main/java/nl/ags/picum/location/gps/Location.java index a37c65a..2d9db85 100644 --- a/app/src/main/java/nl/ags/picum/location/gps/Location.java +++ b/app/src/main/java/nl/ags/picum/location/gps/Location.java @@ -52,6 +52,13 @@ public void onReceive(Context context, Intent intent) { }; } + public void stop() { + + fusedLocationClient.removeLocationUpdates(getLocationCallback()); + this.isRunning = false; + + } + @SuppressLint("MissingPermission") //you must listen to LocationObserver.onLocationUpdate() for the returnvalue of this method private void getLastLocation() { diff --git a/app/src/main/java/nl/ags/picum/mapManagement/MapManager.java b/app/src/main/java/nl/ags/picum/mapManagement/MapManager.java index c93a3d2..694d25a 100644 --- a/app/src/main/java/nl/ags/picum/mapManagement/MapManager.java +++ b/app/src/main/java/nl/ags/picum/mapManagement/MapManager.java @@ -181,6 +181,10 @@ public void startGPSUpdates() { locationService.start(this); } + public void stopGPSUpdates(){ + locationService.stop(); + } + @Override public void onLocationError() { // On Error, log the error @@ -323,6 +327,7 @@ private void sortPointByVisited(Point currentLocation) { public void stopRoute(Route route){ DataStorage dataStorage = AppDatabaseManager.getInstance(context); dataStorage.stopRoute(route); + stopGPSUpdates(); } private void markRouteOfSight(Waypoint waypoint) {