Skip to content

Instantly share code, notes, and snippets.

@manuelvicnt
Created March 23, 2021 06:49
Show Gist options
  • Save manuelvicnt/0e1455e3705240b38a12cafa52fdb48b to your computer and use it in GitHub Desktop.
Save manuelvicnt/0e1455e3705240b38a12cafa52fdb48b to your computer and use it in GitHub Desktop.
class LocationActivity : AppCompatActivity() {
// Coroutine listening for Locations
private var locationUpdatesJob: Job? = null
override fun onStart() {
super.onStart()
locationUpdatesJob = lifecycleScope.launch {
locationProvider.locationFlow().collect {
// New location! Update the map
}
}
}
override fun onStop() {
// Stop collecting when the View goes to the background
locationUpdatesJob?.cancel()
super.onStop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment