From 3e71f01c20fc339367ca11ffdb480895e21db1cd Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Thu, 22 Sep 2016 00:34:10 -0700 Subject: [PATCH] Fix bug where stopping stopwatch from notification in a restarted process was not clearing the laps --- .../stopwatch/StopwatchNotificationService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/stopwatch/StopwatchNotificationService.java b/app/src/main/java/com/philliphsu/clock2/stopwatch/StopwatchNotificationService.java index dca322a..1f087f3 100644 --- a/app/src/main/java/com/philliphsu/clock2/stopwatch/StopwatchNotificationService.java +++ b/app/src/main/java/com/philliphsu/clock2/stopwatch/StopwatchNotificationService.java @@ -154,8 +154,21 @@ public class StopwatchNotificationService extends ChronometerNotificationService // says and tell StopwatchFragment to stop itself. The latter would also stop the // chronometer view if the fragment is still in view (i.e. app is still open). mCurrentLap = null; - mUpdateHandler.asyncClear(); - stopSelf(); + // If this service instance is running in a process different from the one it + // was originally started in, then this AsyncTask will not finish executing + // before stopSelf() is called; as such, the laps table will NOT be cleared. + // This problem does not occur when the service is running in its + // original process. +// mUpdateHandler.asyncClear(); +// stopSelf(); + // A workaround is to place both calls in the SAME thread. + new Thread(new Runnable() { + @Override + public void run() { + mUpdateHandler.getTableManager().clear(); + stopSelf(); + } + }).start(); } @Override