Skip to content

Instantly share code, notes, and snippets.

@manuelvicnt
Created March 23, 2021 06:50
Show Gist options
  • Save manuelvicnt/00222456423cbe1bf5cca2cb73d2db88 to your computer and use it in GitHub Desktop.
Save manuelvicnt/00222456423cbe1bf5cca2cb73d2db88 to your computer and use it in GitHub Desktop.
class LocationActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Collects from the flow when the lifecycle is at least STARTED and
// STOPS the collection when it's STOPPED.
// It automatically restarts collecting when the lifecycle is STARTED again.
lifecycleOwner.addRepeatingJob(Lifecycle.State.STARTED) {
locationProvider.locationFlow().collect {
// New location! Update the map
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment