Skip to content

Commit

Permalink
Dispatch Android Lifecycle add and remove observer on main thread (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
alarochelle authored Aug 25, 2023
1 parent bcb8778 commit 16145b9
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import com.mirego.trikot.foundation.concurrent.dispatchQueue.UIThreadDispatchQueue
import com.mirego.trikot.streams.reactive.BehaviorSubjectImpl
import org.reactivestreams.Publisher

Expand All @@ -21,11 +22,17 @@ actual class ApplicationStatePublisher :

override fun onFirstSubscription() {
super.onFirstSubscription()
lifecycle.addObserver(this)

UIThreadDispatchQueue().dispatch {
lifecycle.addObserver(this)
}
}

override fun onNoSubscription() {
lifecycle.removeObserver(this)
UIThreadDispatchQueue().dispatch {
lifecycle.removeObserver(this)
}

super.onNoSubscription()
}

Expand Down

0 comments on commit 16145b9

Please sign in to comment.