https://grokonez.com/android/kotlin-http-call-with-asynctask-example-android
Kotlin HTTP Call with AsyncTask example | Android
In this tutorial, we’re gonna look at way to implement HTTP Call with AsyncTask
to get data from Yahoo Weather API.
AsyncTask
to implement asynchronous HTTP request to Yahoo Weather API:
To work with AsyncTask
, we must create its subclass, then override at least one method named doInBackground()
:
class GetWeatherAsyncTask : AsyncTask() {
override fun onPreExecute() {
// Before doInBackground
}
override fun doInBackground(vararg params: Params?): Progress {
// ...
publishProgress(progressResult)
return result
}
override fun onProgressUpdate(vararg values: Progress?) {
// use progressResult to do things such as updating UI...
}
override fun onPostExecute(result: Result?) {
// Done: use result which is returned from doInBackground()
}
}
HttpURLConnection
by calling URL.openConnection()
getInputStream()
method (inputStream
field in Kotlin)More at:
https://grokonez.com/android/kotlin-http-call-with-asynctask-example-android
Kotlin HTTP Call with AsyncTask example | Android
#kotlin #asynctask #android