Image for post
Image for post

This is my first post on Medium. I am so happy to share with you how I stopped worrying about async tasks after moving to Kotlin. I don’t want to write about how miserable it is to work on Android AsyncTasks and complication they add.

dependencies {
compile "org.jetbrains.anko:anko-commons:$anko_version"

// do background task here

//update UI thread after completing task
doAsync {
isValidUrl = false
cxn = url.openConnection() as HttpURLConnection
cxn.requestMethod = "GET"
cxn.useCaches = false
cxn.setRequestProperty("Cache-Control", "no-cache")
if (cxn.responseCode == HttpURLConnection.HTTP_OK) {
Log.d("Connection", "Success !" + cxn.responseCode)
isValidUrl = true
} else {
Log.d("Connection", "Fail !" + cxn.responseCode)
isValidUrl = false
uiThread {
// do valid url stuff


Software engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store