diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt index 58ccb3a087b4b435c7eda5b00d3e178bc859b085..3ffcca9e74b2843cca24247f0a49f96122ccda99 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt @@ -65,8 +65,8 @@ import org.microg.gms.maps.mapbox.utils.toMapbox private fun LongSparseArray.values() = (0 until size()).mapNotNull { valueAt(it) } -fun runOnMainLooper(method: () -> Unit) { - if (Looper.myLooper() == Looper.getMainLooper()) { +fun runOnMainLooper(forceQueue: Boolean = false, method: () -> Unit) { + if (!forceQueue && Looper.myLooper() == Looper.getMainLooper()) { method() } else { Handler(Looper.getMainLooper()).post { @@ -833,7 +833,7 @@ class GoogleMapImpl(context: Context, var options: GoogleMapOptions) : AbstractG * null), otherwise that results in other problems (e.g. Gas Now app not * initializing). */ - mapView?.post { + runOnMainLooper(forceQueue = true) { Log.d(TAG, "Invoking callback now: map cannot be initialized because it is not shown (yet)") runCallback() }