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

Conversation

alarochelle
Copy link
Contributor

Description

Android Lifecycle::addObserver and Lifecycle::removeObserver should only be called on the main thread, this PR makes sure that these functions are always called on the main thread.

Motivation and Context

This was somewhat unclear in Trikot and could cause crashes in apps subscribing to the ApplicationStatePublisher when subscribing/unsubscribing. Trikot should make sure that these functions are called from the main thread.

How Has This Been Tested?

Tested in my application.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@alarochelle alarochelle changed the title Dispatch Android Lifecycle add and remove observer on main thread Dispatch Android Lifecycle addObserver and removeObserver on main thread Aug 24, 2023
@@ -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 🙂

@alarochelle alarochelle merged commit 16145b9 into master Aug 25, 2023
1 check passed
@alarochelle alarochelle deleted the fix/application-state-main-thread branch August 25, 2023 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants