Skip to content

Commit

Permalink
Fix lifecycle of looper thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jrothfeder committed Oct 20, 2023
1 parent 1ae6aa4 commit dcce143
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ internal object SessionLifecycleClient {
sendLifecycleEvent(SessionLifecycleService.BACKGROUNDED)
}

/**
* Perform initialization that requires cleanup
*/
fun started() {
if (!handlerThread.isAlive) { handlerThread.start() }
}

/**
* Cleanup initialization
*/
fun stopped() {
handlerThread.quit()
}

/**
* Sends a message to the [SessionLifecycleService] with the given event code. This will
* potentially also send any messages that have been queued up but not successfully delivered to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ internal object SessionsActivityLifecycleCallbacks : ActivityLifecycleCallbacks

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = Unit

override fun onActivityStarted(activity: Activity) = Unit
override fun onActivityStarted(activity: Activity) = SessionLifecycleClient.started()

override fun onActivityStopped(activity: Activity) = Unit
override fun onActivityStopped(activity: Activity) = SessionLifecycleClient.stopped()

override fun onActivityDestroyed(activity: Activity) = Unit

Expand Down

0 comments on commit dcce143

Please sign in to comment.