Skip to content

Commit 6b0e396

Browse files
committed
chore: Code cleanup
1 parent d2ab6f0 commit 6b0e396

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

complete/src/main/java/com/example/android/whileinuselocation/ForegroundOnlyLocationService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ForegroundOnlyLocationService : LifecycleService() {
7272
lateinit var repository: LocationRepository
7373

7474
// Get a reference to the Job from the Flow so we can stop it from UI events
75-
private lateinit var locationFlow: Job
75+
private var locationFlow: Job? = null
7676

7777
override fun onCreate() {
7878
super.onCreate()
@@ -177,7 +177,7 @@ class ForegroundOnlyLocationService : LifecycleService() {
177177
fun unsubscribeToLocationUpdates() {
178178
Log.d(TAG, "unsubscribeToLocationUpdates()")
179179

180-
locationFlow.cancel()
180+
locationFlow?.cancel()
181181
SharedPreferenceUtil.saveLocationTrackingPref(this, false)
182182
}
183183

complete/src/main/java/com/example/android/whileinuselocation/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
115115
lateinit var repository: LocationRepository
116116

117117
// Get a reference to the Job from the Flow so we can stop it from UI events
118-
private lateinit var locationFlow: Job
118+
private var locationFlow: Job? = null
119119

120120
override fun onCreate(savedInstanceState: Bundle?) {
121121
super.onCreate(savedInstanceState)
@@ -283,7 +283,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
283283
}
284284

285285
private fun unsubscribeToLocationUpdates() {
286-
locationFlow.cancel()
286+
locationFlow?.cancel()
287287
foregroundOnlyLocationService?.unsubscribeToLocationUpdates()
288288
}
289289
}

complete/src/main/java/com/example/android/whileinuselocation/data/SharedLocationManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SharedLocationManager @Inject constructor(
2828
) {
2929

3030
private val _receivingLocationUpdates: MutableStateFlow<Boolean> =
31-
MutableStateFlow<Boolean>(false)
31+
MutableStateFlow(false)
3232

3333
/**
3434
* Status of location updates, i.e., whether the app is actively subscribed to location changes.

0 commit comments

Comments
 (0)