Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch Android Lifecycle addObserver and removeObserver on main thread #179

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could reuse the same dispatch queue for both methods, but that's fine like that too 🙂

lifecycle.addObserver(this)
}
}

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

super.onNoSubscription()
}

Expand Down
Loading