File tree 2 files changed +4
-6
lines changed
src/main/java/com/example/android/whileinuselocation/data
2 files changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ dependencies {
65
65
66
66
implementation ' com.google.android.material:material:1.3.0'
67
67
68
+ // To use trySend() instead of offer() in callbackFlow (see https://github.com/Kotlin/kotlinx.coroutines/issues/974)
69
+ implementation ' org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
70
+
68
71
// Hilt for dependency injection
69
72
implementation " com.google.dagger:hilt-android:$hilt_version "
70
73
kapt " com.google.dagger:hilt-compiler:$hilt_version "
Original file line number Diff line number Diff line change @@ -71,12 +71,7 @@ class SharedLocationManager constructor(
71
71
override fun onLocationResult (result : LocationResult ? ) {
72
72
result ? : return
73
73
Log .d(TAG , " New location: ${result.lastLocation.toText()} " )
74
- try {
75
- offer(result.lastLocation) // emit location into the Flow using ProducerScope.offer
76
- } catch (e: Exception ) {
77
- // nothing to do
78
- // Channel was probably already closed by the time offer was called
79
- }
74
+ trySend(result.lastLocation)
80
75
}
81
76
}
82
77
You can’t perform that action at this time.
0 commit comments