-
-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace usage of android.os.AsyncTask
with Kotlin Coroutines
#2436
Comments
Five cents from a developer using Kotlin: Migrating to Kotlin coroutines is something that should not be done in isolation only to replace With Kotlin's suspending functions, the API to initialize the map could look like this, instead of juggling with callbacks: suspend fun initMap() {
val map = mapView.getMap()
val style = map.setStyle("mapstyle.json")
style.addImage("someImg", getDrawable(R.drawable.someImg))
// ...
} These look like blocking calls, and that's the point, that you can write suspending code like normal code. In fact, what I did was to write extension functions to wrap the calls for my use into a suspending API to profit of this convenience myself. E.g. suspend fun MapView.awaitGetMap(): MapLibreMap = suspendCoroutine { cont ->
getMapAsync { cont.resume(it) }
} To make a blocking API that has no callback suspending, one would e.g. suspend fun Style.awaitAddImage(name: String, bitmap: Bitmap) {
withContext(IO) { addImage(name, bitmap) }
} Now, since the native part of MapLibre handles most of the asynchronousness, I guess internally it does make sense to stay with a callback-based approach. So, take my comment with a grain of salt, I reckon it is probably not that helpful / applicable. |
I believe all these AsyncTask calls were removed as part of issue 1607. I do see a couple of AsyncTask calls, but only in Java code, not Kotlin… not sure where that Java code is actually used. |
This bounty can be paid out, PR is ready but we should hold off merging for a bit because it is a breaking change. |
As mentioned by @westnordost in this comment AsyncTask is deprecated and we should replace our usage of it with more modern APIs like Kotlin Coroutines.
A developer could claim a bounty under the modernization bounty direction for this work.
The source files using
android.os.AsyncTask
should also be converted to Kotlin.The text was updated successfully, but these errors were encountered: