Last active
February 12, 2022 06:11
-
-
Save manuelvicnt/ea44d3fe8141da46fcb10ce805efe0a3 to your computer and use it in GitHub Desktop.
Revisions
-
manuelvicnt revised this gist
Nov 4, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ class LocationActivity : AppCompatActivity() { // Listen to multiple flows lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { // As collect is a suspend function, if you want to collect // multiple flows in parallel, you need to do so in // different coroutines -
manuelvicnt revised this gist
Sep 13, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ class LocationActivity : AppCompatActivity() { // Listen to one flow in a lifecycle-aware manner using flowWithLifecycle lifecycleScope.launch { locationProvider.locationFlow() .flowWithLifecycle(lifecycle, Lifecycle.State.STARTED) .collect { // New location! Update the map } -
manuelvicnt revised this gist
Jun 1, 2021 . 1 changed file with 23 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,11 +2,29 @@ class LocationActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Listen to one flow in a lifecycle-aware manner using flowWithLifecycle lifecycleScope.launch { locationProvider.locationFlow() .flowWithLifecycle(this, Lifecycle.State.STARTED) .collect { // New location! Update the map } } // Listen to multiple flows lifecycleScope.launch { lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { // As collect is a suspend function, if you want to collect // multiple flows in parallel, you need to do so in // different coroutines launch { flow1.collect { /* Do something */ } } launch { flow2.collect { /* Do something */ } } } } } } -
manuelvicnt created this gist
Mar 23, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ class LocationActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) locationProvider.locationFlow() .flowWithLifecycle(this, Lifecycle.State.STARTED) .onEach { // New location! Update the map } .launchIn(lifecycleScope) } }