Created
March 23, 2021 06:49
-
-
Save manuelvicnt/0e1455e3705240b38a12cafa52fdb48b 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() { | |
// 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