@@ -36,7 +36,7 @@ class RemoteService : Service(), ForegroundHooks {
3636 @Inject
3737 lateinit var notificationService: NotificationService
3838
39- private lateinit var threadPoolExecutor: ExecutorService
39+ private var threadPoolExecutor: ExecutorService ? = null
4040 private lateinit var scope: Scope
4141
4242 override fun onBind (intent : Intent ? ): IBinder {
@@ -56,8 +56,9 @@ class RemoteService : Service(), ForegroundHooks {
5656 CommandRegistration .register(remoteController, scope)
5757 threadPoolExecutor = Executors .newSingleThreadExecutor {
5858 Thread (it, " message-thread" )
59+ }.apply {
60+ execute(remoteController)
5961 }
60- threadPoolExecutor.execute(remoteController)
6162
6263 remoteController.executeCommand(MessageEvent (UserInputEventType .StartConnection ))
6364 discovery.startDiscovery()
@@ -71,7 +72,7 @@ class RemoteService : Service(), ForegroundHooks {
7172 remoteController.executeCommand(MessageEvent (UserInputEventType .CancelNotification ))
7273 remoteController.executeCommand(MessageEvent (UserInputEventType .TerminateConnection ))
7374 CommandRegistration .unregister(remoteController)
74- threadPoolExecutor.shutdownNow()
75+ threadPoolExecutor? .shutdownNow()
7576 Timber .d(" Background Service::Destroyed" )
7677 Toothpick .closeScope(this )
7778 }
0 commit comments