From c4f72ab482e12174bec90d7bde9b71bddd31d8d7 Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Mon, 25 Sep 2023 16:07:55 +0200 Subject: [PATCH] Attempt to fix locationManager crash on Android (#2803) * Call parent destructor as the last thing * Check if locationManager is validbefore removing updates --- .../src/uk/co/lutraconsulting/PositionTrackingService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java b/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java index e7c53310a..eb5bfb7b7 100644 --- a/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java +++ b/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java @@ -83,9 +83,10 @@ public IBinder onBind( Intent intent ) { @Override public void onDestroy() { - super.onDestroy(); - locationManager.removeUpdates(this); + if (locationManager != null) { + locationManager.removeUpdates(this); + } // Close the FileOutputStream when the service is destroyed try { @@ -96,6 +97,8 @@ public void onDestroy() { e.printStackTrace(); sendStatusUpdateMessage("ERROR #SILENT: Could not close file stream: " + e.getMessage() ); } + + super.onDestroy(); } public void sendStatusUpdateMessage( String message ) {