Skip to content

Commit

Permalink
Does some of the service cleanup in a delayed manner
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Dec 11, 2020
1 parent aea9f24 commit 9bc2b68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions app/src/main/kotlin/com/kelsos/mbrc/controller/RemoteService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,21 @@ class RemoteService : Service() {
return super.onStartCommand(intent, flags, startId)
}


override fun onDestroy() {
super.onDestroy()
SERVICE_STOPPING = true;
stopForeground(true)
this.unregisterReceiver(receiver)
remoteController.executeCommand(MessageEvent(UserInputEventType.TerminateConnection))
CommandRegistration.unregister(remoteController)
threadPoolExecutor?.shutdownNow()
Toothpick.closeScope(this)

SERVICE_STOPPING = false
SERVICE_RUNNING = false
Timber.d("Background Service::Destroyed")
handler.postDelayed({
remoteController.executeCommand(MessageEvent(UserInputEventType.TerminateConnection))
CommandRegistration.unregister(remoteController)
threadPoolExecutor?.shutdownNow()
Toothpick.closeScope(this)

SERVICE_STOPPING = false
SERVICE_RUNNING = false
Timber.d("Background Service::Destroyed")
}, 150)
}

private inner class ControllerBinder : Binder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ constructor(
Timber.v("Received action ${SocketAction.name(action)}")
when (action) {
RESET -> {
shouldStop = false;
resetState()
startSocket()
cleanupSocket()
Expand Down Expand Up @@ -127,7 +128,6 @@ constructor(

private fun resetState() {
connecting = false
shouldStop = false
numOfRetries = 0
}

Expand Down

0 comments on commit 9bc2b68

Please sign in to comment.