Created
March 23, 2021 07:14
-
-
Save manuelvicnt/e9b4c5fe496b8d9020333f6856bf9b4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocationActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
// Collects from the flow when the View is at least STARTED and | |
// SUSPENDS the collection when the lifecycle is STOPPED. | |
// Collecting the flow cancels when the View is DESTROYED. | |
lifecycleScope.launchWhenStarted { | |
locationProvider.locationFlow().collect { | |
// New location! Update the map | |
} | |
} | |
// Same issue with: | |
// - lifecycleScope.launch { /* Collect from locationFlow() here */ } | |
// - locationProvider.locationFlow().onEach { /* ... */ }.launchIn(lifecycleScope) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment