Skip to content

Commit fa7eb95

Browse files
committed
refactor: Use application-scoped CoroutineScope
Replaced GlobalScope with a custom CoroutineScope in MapsComposeApplication to ensure better lifecycle management for coroutines. Also clarified the comment regarding SDK initialization.
1 parent 0723cc1 commit fa7eb95

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

maps-app/src/main/java/com/google/maps/android/compose/MapsComposeApplication.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ package com.google.maps.android.compose
1616

1717
import android.app.Application
1818
import com.google.maps.android.compose.internal.DefaultGoogleMapsInitializer
19-
import kotlinx.coroutines.DelicateCoroutinesApi
19+
import kotlinx.coroutines.CoroutineScope
2020
import kotlinx.coroutines.Dispatchers
21-
import kotlinx.coroutines.GlobalScope
21+
import kotlinx.coroutines.SupervisorJob
2222
import kotlinx.coroutines.launch
2323

2424
class MapsComposeApplication : Application() {
25-
@OptIn(DelicateCoroutinesApi::class)
25+
26+
private val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
27+
2628
override fun onCreate() {
2729
super.onCreate()
28-
// Note: that this is not a singleton, but it should still effectively load the SDK once
30+
// The DefaultGoogleMapsInitializer is not a singleton, but the Maps SDK is initialized just once.
2931

30-
GlobalScope.launch(Dispatchers.Main) {
32+
applicationScope.launch {
3133
DefaultGoogleMapsInitializer().initialize(
3234
context = this@MapsComposeApplication,
3335
forceInitialization = false

0 commit comments

Comments
 (0)