improving server shutdown to try to get rid of the 'will not shutdown' problem.

This commit is contained in:
Graham Jones
2020-11-06 20:44:19 +00:00
parent 36285f0d09
commit f0d66947cd
2 changed files with 34 additions and 16 deletions

View File

@@ -41,6 +41,20 @@ public class LocationFinder implements LocationListener
mLocationListener = this; mLocationListener = this;
} }
public void destroy() {
// Cancel location updates
mLocationManager.removeUpdates(this);
// cancel the timeout timer
if (mTimeoutTimer != null) {
mTimeoutTimer.cancel();
mTimeoutTimer.purge();
mTimeoutTimer = null;
}
}
public Location getLastLocation() { public Location getLastLocation() {
return mLastLocation; return mLastLocation;
} }
@@ -105,5 +119,6 @@ public class LocationFinder implements LocationListener
public void onProviderDisabled(String s) { public void onProviderDisabled(String s) {
} }
} }

View File

@@ -105,7 +105,7 @@ public class SdServer extends Service implements SdDataReceiver {
private HandlerThread thread; private HandlerThread thread;
private WakeLock mWakeLock = null; private WakeLock mWakeLock = null;
private LocationFinder mLocationFinder; private LocationFinder mLocationFinder = null;
public SdDataSource mSdDataSource; public SdDataSource mSdDataSource;
public SdData mSdData = null; public SdData mSdData = null;
public String mSdDataSourceName = "undefined"; // The name of the data soruce specified in the preferences. public String mSdDataSourceName = "undefined"; // The name of the data soruce specified in the preferences.
@@ -376,18 +376,11 @@ public class SdServer extends Service implements SdDataReceiver {
// Stop the Cancel Alarm Latch timer // Stop the Cancel Alarm Latch timer
stopLatchTimer(); stopLatchTimer();
// Stop the status timer
/*if (dataLogTimer != null) {
Log.v(TAG, "stop(): cancelling Data logger timer");
mUtil.writeToSysLogFile("onDestroy() - cancelling data log timer");
dataLogTimer.cancel();
dataLogTimer.purge();
dataLogTimer = null;
}
*/
// Stop the log Manager // Stop the location finder.
//mLm.close(); if (mLocationFinder != null) {
mLocationFinder.destroy();
}
try { try {
@@ -414,6 +407,8 @@ public class SdServer extends Service implements SdDataReceiver {
mUtil.writeToSysLogFile("SdServer.onDestroy() -error " + e.toString()); mUtil.writeToSysLogFile("SdServer.onDestroy() -error " + e.toString());
} }
super.onDestroy();
} }
@@ -999,13 +994,21 @@ public class SdServer extends Service implements SdDataReceiver {
Log.i(TAG, "SdServer.stopWebServer()"); Log.i(TAG, "SdServer.stopWebServer()");
if (webServer != null) { if (webServer != null) {
webServer.stop(); webServer.stop();
if (webServer.isAlive()) { if (webServer == null) {
Log.w(TAG, "stopWebServer() - server still alive???"); mUtil.writeToSysLogFile("stopWebServer() - server null - server died ok");
Log.v(TAG, "stopWebServer() - server null - server died ok");
} else { } else {
Log.v(TAG, "stopWebServer() - server died ok"); if (webServer.isAlive()) {
Log.w(TAG, "stopWebServer() - server still alive???");
} else {
mUtil.writeToSysLogFile("stopWebServer() - server died ok");
Log.v(TAG, "stopWebServer() - server died ok");
}
} }
webServer = null; //webServer = null;
} }
mUtil.writeToSysLogFile("unregisterig network broadcast receiver");
Log.v(TAG, "unregistering network broadcast receiver");
getApplicationContext().unregisterReceiver(mNetworkBroadcastReceiver); getApplicationContext().unregisterReceiver(mNetworkBroadcastReceiver);
} }