Remove requests to start background thread.
When the activity is being paused or destroyed, we asked the background
thread handling update requests to be stopped. However it is possible
for a request to start the thread is pending. Make sure those are
removed as well.
Since onPause/onDestroy and the request are all handled on the main
thread, there is no race condition between the removal of the request to
start the thread and the call to stopRequestProcessing.
Change-Id: I5eab9fa12d54ce5a5519687946fab8f4c82470b6
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 961c134..017044e 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -290,7 +290,16 @@
mCallerIdThread.start();
}
+ /**
+ * Stops the background thread that processes updates and cancels any pending requests to
+ * start it.
+ * <p>
+ * Should be called from the main thread to prevent a race condition between the request to
+ * start the thread being processed and stopping the thread.
+ */
public void stopRequestProcessing() {
+ // Remove any pending requests to start the processing thread.
+ mHandler.removeMessages(START_THREAD);
mDone = true;
if (mCallerIdThread != null) mCallerIdThread.interrupt();
}