diff --git a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt index bbdcd3e55d27..72755946c9f1 100644 --- a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt +++ b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleClient.kt @@ -21,6 +21,7 @@ import android.content.Context import android.content.Intent import android.content.ServiceConnection import android.os.Handler +import android.os.HandlerThread import android.os.IBinder import android.os.Looper import android.os.Message @@ -54,13 +55,18 @@ internal object SessionLifecycleClient { private var serviceBound: Boolean = false private val queuedMessages = LinkedBlockingDeque(MAX_QUEUED_MESSAGES) private var curSessionId: String = "" + private var handlerThread: HandlerThread = HandlerThread("FirebaseSessionsClient_HandlerThread") + init { + handlerThread.start() + } + /** * The callback class that will be used to receive updated session events from the * [SessionLifecycleService]. */ // TODO(rothbutter) should we use the main looper or is there one available in this SDK? - internal class ClientUpdateHandler : Handler(Looper.getMainLooper()) { + internal class ClientUpdateHandler : Handler(handlerThread.looper) { override fun handleMessage(msg: Message) { when (msg.what) { SessionLifecycleService.SESSION_UPDATED ->