From c85cf2f5aea606550bf08b07f899543ae46a7c7e Mon Sep 17 00:00:00 2001 From: mg4gh Date: Sat, 6 Jul 2024 17:46:14 +0200 Subject: [PATCH] clean exit, if TrackLoggerService was used previously --- .../activity/mgmap/features/control/FSControl.java | 12 ++++++++---- .../mgmap/service/location/TrackLoggerService.java | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mgmap/src/main/java/mg/mgmap/activity/mgmap/features/control/FSControl.java b/mgmap/src/main/java/mg/mgmap/activity/mgmap/features/control/FSControl.java index 2e6f65a3..5582634a 100644 --- a/mgmap/src/main/java/mg/mgmap/activity/mgmap/features/control/FSControl.java +++ b/mgmap/src/main/java/mg/mgmap/activity/mgmap/features/control/FSControl.java @@ -105,10 +105,14 @@ public class FSControl extends FeatureService { activity.startActivity(intent); }; Observer exitObserver = (e) -> { - getActivity().finishAndRemoveTask(); - if (getApplication().baseConfig.getMode() == BaseConfig.Mode.NORMAL){ - System.exit(0); - } + getPref(R.string.FSPosition_pref_GpsOn, false).setValue(false); + getApplication().startTrackLoggerService(getActivity(),false); + getTimer().postDelayed(()->{ + getActivity().finishAndRemoveTask(); + if (getApplication().baseConfig.getMode() == BaseConfig.Mode.NORMAL){ + System.exit(0); + } + },500); }; Observer themesObserver = (e) -> { MGMapActivity activity = getActivity(); diff --git a/mgmap/src/main/java/mg/mgmap/service/location/TrackLoggerService.java b/mgmap/src/main/java/mg/mgmap/service/location/TrackLoggerService.java index 05d81037..3b6b9b40 100644 --- a/mgmap/src/main/java/mg/mgmap/service/location/TrackLoggerService.java +++ b/mgmap/src/main/java/mg/mgmap/service/location/TrackLoggerService.java @@ -101,7 +101,7 @@ public void onCreate() { @Override public int onStartCommand(Intent intent, int flags, int startId) { - + mgLog.i("onStartCommand"); application = (MGMapApplication)getApplication(); if (prefGps.getValue()){ @@ -130,7 +130,7 @@ protected void activateService(){ } catch (NumberFormatException e) { mgLog.e(e); } - mgLog.i("smoothingPeriod="+barometerSmoothingPeriod); + mgLog.i("activateService smoothingPeriod="+barometerSmoothingPeriod); barometerListener = new BarometerListener(application, SensorManager.SENSOR_DELAY_FASTEST, barometerSmoothingPeriod); boolean prefFused = prefCache.get(R.string.FSPosition_pref_FusedLocationProvider, false).getValue(); locationListener = prefFused?new FusedLocationListener(application, this):new GnssLocationListener(application, this); @@ -145,9 +145,12 @@ protected void activateService(){ } protected void deactivateService(){ try { + mgLog.i("deactivateService"); stopForeground(STOP_FOREGROUND_REMOVE); if (locationListener != null) locationListener.deactivate(); if (barometerListener != null) barometerListener.deactivate(); + Intent intent = new Intent(this, TrackLoggerService.class); + stopService(intent); } catch (Exception e) { mgLog.e(e); }