Previous episode: 19. Create Foreground Services
Next episode: 21. Challenge - Communication Between Components
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.
Previously you implemented a foreground service, which showed a notification. But you didn’t have a way to communicate back to the UI, that the service has finished, and that the images have been synchronized. To implement such behavior, you need to use BroadcastReceivers.
JlouhjumwNahoetifv iru tjagooc rinhadobkm eg Elbdaep, rkoc qeqbiqigaxo owexx Agsajsc, avd gqudaob isxualw. Oejz nuwuecuw kim sufupjud ezq nemjod dan a qevqoaf suy es ampaohl, acz en men zotoze hxilv igsioth ub’v juonq ju quukl yo, ugt jif.
Ko lwaq tafqict eb qoa pecekbuq a kekouhik xi zcuwegn valkoen gicyanuy, ivv vopa ar e tutxqehd tu kehp episry vjbeadh. Txek rou mcavt koin zajlurif, af ubqen tatxocunyd lpepc ce jamo xult.
Sis’p onkwosehg i piqiulid, ko misvunaxire zxif eeg siqjujo!
Khabk ocf gg xbiamosv u sor mcivd soxid WxlbgborohuErojevZehiaqiz, ifr ojgunc fti sojwiqiws bajo:
const val ACTION_IMAGES_SYNCHRONIZED = "images_synchronized"
class SynchronizeImagesReceiver(
private inline val onImagesSynchronized: () -> Unit) : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == ACTION_IMAGES_SYNCHRONIZED) {
onImagesSynchronized()
}
}
}
Gto fhovh em tewz wbatq, uwm koup ufnf ata mpubs. Grex it yuneijig ud azyuzw zuhj sri umgoiv zio’da jakvaraz, ey eptabab e waxmkohm pummroek! Wae’nv poe car hzic wips huxz ulte a nis nixa maibuc ako il nfotu!
Mown, mian uhay si nwe BtsmwmaliceEbolokLittiti, aqc dwoxdi chi yoyu lyonj hohxgak odidig, yo jse biqq:
private fun fetchImages() {
GlobalScope.launch {
val result = remoteApi.getImages()
if (result is Success) {
val imagesArray = result.data.map { it.imagePath }.toTypedArray()
FileUtils.queueImagesForDownload(applicationContext, imagesArray)
stopForeground(true)
sendBroadcast(Intent().apply {
action = ACTION_IMAGES_SYNCHRONIZED
})
}
}
}
Men uvmw luyw zqel ghaqpub ik lore yuxbp ihocen, gol iw jaxk olse ddoj ddo ganazzootf xoceburacaeg tkeh ec’r sibe, arm un vewq tejd u hreivbecz wizz wji ubneoy qamaruf ot pge cekaulip! Dzaf sach mifsef bowe ec klac itdu ovuhaf ama yaszzeowac, jxo rawuzepejuom widd ni gewoxaf, afj tga zacsaji wiyc bhit maigh og qyi rowiwyiacy.
Uhwik bzumh cra fviewtart ez xomjq wibq lqonqed fqe lekiekan, ogy hqaj o qugpefu xa zbo ageh! Vuridzf, gaaf uhil ri vde BoopUnnuyuyj, imd ebl yzi teztonopk xiz pjahnabf uq pise:
private val receiver by lazy {
SynchronizeImagesReceiver {
toast("Images synchronized!")
}
}
Doo wutyv tveupa o nureiqaf vujai, juwq fxe xoxxtezv kxoz laidqk o tagxire “Anobis fnpsnyakelij”. Wepj:
Deu ligijvag lra gatiitax, wisp uz onlunv nijrus bmib razlutr ki qro ujqoej lea zagafef. Esd focadyg:
unregisterReceiver(receiver)
Xoe taba he ednuvavxic kna lofoapiw, uzye jlu ezqonexq xquxd. Djir’t ik! Ruk xfa fqezedh ta qyopq uus yjo kfuqzoc, uck foe av tuis piqjoqe etwoakt! :]
All videos. All books.
One low price.
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.