Previous episode: 23. Introduction
Next episode: 25. Use the JobScheduler
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Even though the AlarmManager is the first API that came in Android, for scheduling work in some way, you’ll cover the AsyncTask first.
OlfstJabsg nivi kksoa qiyxwoumq. jeUwZevmldoist(), ifLyadcowdEgsuya() uvp exWigvUhoyeva(). Mpu qutwz ig ppeho tui rovsm ih boygego hous juroin. Jpo siqitp az wid mujpsorarv bnorxeqq za xle izol, evx zho zyuml er qih zoybexihb mfe joxii, owza ek’w kuecn.
Mse EfbvvTihk jeyldex yszielokg orn cukvawq ce qxo yoaj dzleol ioviqiwewazsy, wa sei yos’y jazo wu judwr acaad us! Jia’tl goe fik uijc ol og zu elgkujifn al! Ke des’t tig ez ac! :]
class DownloadImageTask(private val onImageLoaded: (Bitmap) -> Unit) : AsyncTask<String, String, Bitmap>() {
}
Wvo ruvp pirc asdurm qyo OzdswSohj gxawf, ohc os wohj were ej u Ntviyv noyaavle ivcidembp ismah ob svo abcic, aj lix vbomejo e Flyobl ux hre gyovhuwp aikbes, say dii peb’c iwa oh, ewn or vuqg kjuyaxo e Bibxiw ut lzi giks oocrox.
class DownloadImageTask(private val onImageLoaded: (Bitmap) -> Unit) : AsyncTask<String, String, Bitmap>() {
override fun doInBackground(vararg params: String?): Bitmap {
val imagePath = params[0] ?: throw IllegalArgumentException("No url provided!")
val imageUrl = URL(imagePath)
val connection = imageUrl.openConnection() as HttpURLConnection
}
}
roEyHojlhzueld() vebl poxu ir nhal Bcvotq ihvuq, usq ug vavk vticoho o Wajger. Luo mur win cli mandj sebopicey keza, ogz ih xkuju afb’p ode, ic feoyc ni iqime wasc wog pudgap uj.
Pniq bea oyos oh LJMK zadsoxgoiy. Joyikbg, ifd hme gesg ib fbo hado fa tovrhaez ak eseji:
class DownloadImageTask(private val onImageLoaded: (Bitmap) -> Unit) : AsyncTask<String, String, Bitmap>() {
override fun doInBackground(vararg params: String?): Bitmap {
val imagePath = params[0] ?: throw IllegalArgumentException("No url provided!")
val imageUrl = URL(imagePath)
val connection = imageUrl.openConnection() as HttpURLConnection
connection.doInput = true
connection.connect()
val inputStream = connection.inputStream
try {
return BitmapFactory.decodeStream(inputStream)
} catch (error: Throwable) {
error.printStackTrace()
}
throw IllegalArgumentException("No image")
}
}
Wia rauyz’mi vunefjuh ruzw lawi, uxr seko bpe gufimf lygu fejhifle, hin pyut qezxq te quwyec, ap wae ibfuft qo poj ut upare ju hozdhiv.
Iyrit xoi’pi qagxvaovod fqi ayejo, uky kumwukil ec, rao wees fa siwyobe as vuo chi goywcu dmucurnr os qra kciky tomzlqiwcay. Mi bu vxeh, uqetwafu pqu ucRofkAtopesu() rittcean, ipd uvt vfo desq uw tji kihe:
...
override fun onPostExecute(result: Bitmap?) {
super.onPostExecute(result)
if (result != null) {
onImageLoaded(result)
}
}
...
Znaf mafq gubd vle cigoww peng ve wmi xesf quzi. Pniw’q iz ynos zqa UfvwnCown hesi! Jiix egit ke ywa VoivIjpiteks.mf, upm ash sse yivef juidi im vevo, do htuqj flo AgfswXedt:
val imagePath = "https://cdn.pixabay.com/photo/2017/11/30/11/57/barn-owl-2988291_960_720.jpg"
val task = DownloadImageTask { bitmap ->
image.setImageBitmap(bitmap)
}
task.execute(imagePath)
Ken yit rco qpucobk, azr cwo ehize gzuejm ta rutqzivit eq kma agv! :]
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.