Understanding and Using Services in Android: Background & Foreground Services

  Рет қаралды 72,490

Codeible

Codeible

Күн бұрын

If you find this video helpful, please Like, Share, and Subscribe to support the channel!
Download project: codeible.com/coursefiles/andr...
View article on Codeible.com: codeible.com/view/videotutori...
Hello, in this video, I will show you how to utilize Background and Foreground Services in Android.
There are 3 types of services in Android - Background, Foreground, and Bound. Each of these terms are misleading because it is not describing the behavior of how each service are used, but it is describing how they are terminated.
For Android Developers, a Service is a component that runs on the background to perform long-running tasks.
A Background Service is a service that runs only when the app is running so it’ll get terminated when the app is terminated.
A Foreground Service is a service that stays alive even when the app is terminated.
And a Bound Service is a service that runs only if the component it is bound to is still active.
0:00 - Start of video
0:12 - Background, Foreground, and Bound Services
0:50 - Creating and Demoing Background Services
3:42 - Creating and Demoing Foreground Services
11:12 - Restarting a Foreground Service on Device Reboot using BroadcastReceiver
Support Codeible on Patreon!
/ codeible
Reddit:
/ codeible
Follow on Pinterest:
/ codeible
Follow on Instagram:
/ codeibleig
Follow on Twitter:
intent/follow?ori...

Пікірлер: 113
@roman71717
@roman71717 2 жыл бұрын
This is one of the best-explained tutorials I have watched!! Thank you :)
@DebugWithAdam
@DebugWithAdam 2 жыл бұрын
I have been looking for something like this to complete our 5 months flutter project, finally I got the solution from your content. Thank you so much, looking forward to seeing more contents
@frax84
@frax84 2 жыл бұрын
I give you 3C score for this video: Concise, Complete, Clear. Really good explanation. Thank you
@lubuntumleto5052
@lubuntumleto5052 Жыл бұрын
Good example how simple it could be, when guide is so clear and opened step by step, thank you sir.
@teladoum9
@teladoum9 Жыл бұрын
Thank you. I'm looking for this video longtime. Be blessed. Soyez béni mon frère.
@truthonly_
@truthonly_ 2 жыл бұрын
Ultimate content. I never understood services that easily ever before. Thank you 🤟
2 жыл бұрын
Thank you for clear and worked practice even on API 28. Great work. More android tutorials please.
@strawberryinc.2275
@strawberryinc.2275 Жыл бұрын
i really needed this, @Codeible, thank you big time.
@itallstartedwhen
@itallstartedwhen 2 жыл бұрын
Best video on the topic on KZfaq, so well explained 😍😍😍😍😍😍😍😍
@satwikkar7761
@satwikkar7761 2 жыл бұрын
Best video on utube regarding services in android... 👍👍👍👍
@ravindrashekhar4419
@ravindrashekhar4419 2 жыл бұрын
Clear Cut simple and Illustrative video, good for starters.
@drakohgaming5131
@drakohgaming5131 7 ай бұрын
you're salve my life bro, i have weeks searching this info. Thanksh! like and new sub
@georgenady7375
@georgenady7375 2 жыл бұрын
man ! thank you very much for your awsom explaination for that topic
@onwodoh
@onwodoh Жыл бұрын
This was a good video. I learned so much in a short amount of time!
@involved1984
@involved1984 9 ай бұрын
Amazing and simple explaination. Thanks. Keep up the good work 👍
@joshuantw
@joshuantw 2 жыл бұрын
Awesome video my dude. Really clear.
@TupolevSlaVTuber
@TupolevSlaVTuber Жыл бұрын
nice tut crystal clear and spot on
@MauricioSouza-93
@MauricioSouza-93 3 ай бұрын
Great explanation!! Thanks!!
@hassanesilverlight1550
@hassanesilverlight1550 2 жыл бұрын
Thank you. Best Service tutorial ever.
@mohdfaris9054
@mohdfaris9054 2 жыл бұрын
Terbaik servies dia..tapi home Macan setan dia...malu.out site..setan bertanduk lima..celaka
@abunaser3525
@abunaser3525 2 жыл бұрын
I left java 3 years ago .and start using kotlin . But your explanation is So good that I end up subscribing to your channel. Hope you start using compose multiplatform 🙂 this is the very first video from you that I watched .so don't you if you are already using kotlin . Anyway nice video ..
@myhealthobs5290
@myhealthobs5290 Жыл бұрын
I wonder who organised the naming if foreground vs background. Unbelievable, thanks for clearing it up
@drygordspellweaver8761
@drygordspellweaver8761 Жыл бұрын
lol it was Larry Ellison, the Devil himself.
@okeuwechue9238
@okeuwechue9238 Жыл бұрын
Very clear and direct explanation of the different service types. 👍 However you mention that multiple instances of the service will get created if started multiple times, but this isn't so; there will only be one instance of the service object but its onStartCommand() function will be invoked those multiple times.
@Somerandomnessvvv
@Somerandomnessvvv 2 жыл бұрын
Come onnn this gotta be one of the best practical service tuts. Can’t wait to see you work with kotlin.
@mohdfaris9054
@mohdfaris9054 2 жыл бұрын
Yesss good job baby..setan kocak bini orang sampai dsana ..party sex u setan...
@petermolnar6017
@petermolnar6017 8 ай бұрын
Thanks for this great video!
@asimjmi2010
@asimjmi2010 2 жыл бұрын
Nice explanation.... you're awesome man 👍🏻
@shubhm_agarwal
@shubhm_agarwal 2 жыл бұрын
Great explanation helped me a lot. Hence subscribed.
@yacoubasylla7358
@yacoubasylla7358 2 жыл бұрын
Thank you very much
@suche_cz
@suche_cz 2 жыл бұрын
Thank you, this video was really usefull
@D-Coder440
@D-Coder440 17 күн бұрын
Osm! Thank you bro for this helpful video
@darklaker
@darklaker 2 жыл бұрын
The best explanation for services I've found and it's just what I needed. I would add a handler to show a toast message from the service. Handler mainHandler = new Handler(getMainLooper()); mainHandler.post(new Runnable() { @Override public void run() { // Do your stuff here related to UI, e.g. show toast Toast.makeText(getApplicationContext(), "Message from Service", Toast.LENGTH_SHORT).show(); } });
@maliksoft3675
@maliksoft3675 2 жыл бұрын
very nice thanks for this video.
@yusufmustari
@yusufmustari 2 жыл бұрын
Thanks bro... very helpfull
@alexmercerind
@alexmercerind 7 ай бұрын
Very useful!!!
@hrishikeshpator3853
@hrishikeshpator3853 Жыл бұрын
Thank you❤
@NielAclag
@NielAclag 2 жыл бұрын
thank you!!
@LasWegas
@LasWegas Жыл бұрын
Great!
@vr_connoisseur
@vr_connoisseur Жыл бұрын
nice video, helped me so much!
@user-up7zn7sn4f
@user-up7zn7sn4f 2 жыл бұрын
I hope to learn how to play the list view of music through the service by Raw or Assest folder to work in background long time ... thanks for this video
@explorer1125
@explorer1125 Жыл бұрын
Very good explanation..!!👏
@NghiaNguyen-hn5st
@NghiaNguyen-hn5st 2 жыл бұрын
its amazingg thanks you
@androidlearners9163
@androidlearners9163 2 жыл бұрын
Thanks alot bro
@kemaldeveli8195
@kemaldeveli8195 2 жыл бұрын
I like your videos a lot please share more videos with us
@mediaatech7992
@mediaatech7992 2 жыл бұрын
so thanks you bro
@AshooOffice
@AshooOffice Жыл бұрын
Thnks a lot
@sedatdemirtas9955
@sedatdemirtas9955 2 жыл бұрын
Thanks
@Hanna-ir6te
@Hanna-ir6te 2 жыл бұрын
Thanks for this tutorial. May I know how how to create second application which will run in the background service when first application is processing without interacting of first app?
@mdrashid6002
@mdrashid6002 2 ай бұрын
Great Thanks boss for such a clear explanation, What about the Bound Services??
@hometv8446
@hometv8446 2 жыл бұрын
Very helpful
@marwenhammami9575
@marwenhammami9575 Жыл бұрын
Thanks
@Hanna-zj1gk
@Hanna-zj1gk 2 жыл бұрын
This tutorial is very helpful. May I know how how to create second application which will run in the background service when first application is processing without interacting of first app?
@alokeshnath4269
@alokeshnath4269 2 жыл бұрын
I have tested this on real device when I restart the device I didn't see the notification that you got...? Is there anything to add more?
@codingfeed9206
@codingfeed9206 2 жыл бұрын
Im your new Subscriber because of your video i easily understand some coding stuff
@codingfeed9206
@codingfeed9206 2 жыл бұрын
Thank you
@avigneswaranwaran
@avigneswaranwaran 2 жыл бұрын
Awesome
@llothar68
@llothar68 8 ай бұрын
If i use NDK to run a C++ library, which service should i use to run the code out of process? Sometimes C++ crashs and i want them to take a service down but not the whole app. So i need to do the same as all webbrowsers do it.
@adnananik7586
@adnananik7586 Жыл бұрын
thanks
@virgile8453
@virgile8453 2 жыл бұрын
amazing
@pietrolanuti2571
@pietrolanuti2571 3 күн бұрын
in android 14 sdk version 34, when the app closes the foregroundservice also closes. Are there any solutions for this? Thanks
@AnuragSingh-eb6of
@AnuragSingh-eb6of Жыл бұрын
How I can block wifi internet from using to a specific app in aops /os
@derkeks814
@derkeks814 2 жыл бұрын
Great Video! Is there a way to stop the Service by code?
@moe_shah_0078
@moe_shah_0078 Жыл бұрын
How would you stop the foreground service?
@sandeepchauhan7918
@sandeepchauhan7918 2 жыл бұрын
Very good explanation.
@sandeepchauhan7918
@sandeepchauhan7918 2 жыл бұрын
@instagram I cant answer It. I have limited knowledge and experiance.
@aymaneme96
@aymaneme96 2 жыл бұрын
waaaaaaaaaaaaaaaaaaaaaaaaaw ma bro its amazing
@musicjagot1632
@musicjagot1632 10 ай бұрын
Android 12 & 13 How long will it be running Foreground service??
@cloner_8852
@cloner_8852 2 жыл бұрын
I have created an alarm app in Android 11, but it does not work when the app is closed. Does anyone know where the problem is ??
@lucasmontec
@lucasmontec Жыл бұрын
I believe from what I read on google documentation, that there is no need to check if the service is running. Apparently, that was a bug.
@Hong-Mu
@Hong-Mu 2 жыл бұрын
useful
@habibmalim6178
@habibmalim6178 2 жыл бұрын
so helpful thank you very much 😊 does it work with all android versions specially oreo or higher ?
@Codeible
@Codeible 2 жыл бұрын
Hello it should work for API 26 or higher.
@hamsakumar4535
@hamsakumar4535 2 жыл бұрын
@@Codeible Any alternate service to run for below 26.
@67Diadem
@67Diadem 2 жыл бұрын
After restarting the app background service is not displaying in the notification area. I have tested on my mobile. Please help 🥺
@mychannel-jb3zk
@mychannel-jb3zk Жыл бұрын
I understand that telegram had an unlimited open service in background, how it is posible?
@alisheykhi9649
@alisheykhi9649 2 жыл бұрын
great bro , but im looking for Bound service impl 🙂
@ArturoDevA
@ArturoDevA 2 жыл бұрын
fail when stop service and after 10 seconds enable
@jeremyheng8573
@jeremyheng8573 2 жыл бұрын
Thank you for the sharing! Any idea we can get Firestore document update if our app is terminated?
@Codeible
@Codeible 2 жыл бұрын
Hello, Yes you can.
@jeremyheng8573
@jeremyheng8573 2 жыл бұрын
@@Codeiblewhat method should we implement to update client document if app is terminated
@Codeible
@Codeible 2 жыл бұрын
@@jeremyheng8573 What do you mean? You can just update the document like normal using the Firebase API for Android.
@mohdfaris9054
@mohdfaris9054 2 жыл бұрын
Hello good job.....nerka u all setan...nice...tqqqq
@tanmaysinghal8370
@tanmaysinghal8370 2 жыл бұрын
For me only one notification was being created even without checking if the service is running already or not....
@mohdfaris9054
@mohdfaris9054 2 жыл бұрын
Ready....hahahhah...manpussss
@yeongshyhhaw9374
@yeongshyhhaw9374 2 жыл бұрын
how to stop..
@slcsb116
@slcsb116 Жыл бұрын
Can you make this in kotlin ?
@gunturdarmawan1513
@gunturdarmawan1513 2 жыл бұрын
U have udemy courses?
@priyanshusahu8024
@priyanshusahu8024 2 жыл бұрын
i cant able to receive broadcast after my app has been killed
@jaimitkumarpanchal7603
@jaimitkumarpanchal7603 Жыл бұрын
if service stops after few seconds then what to do?
@Codeible
@Codeible Жыл бұрын
If the service stops, it could mean that the task is finished. If you want to keep it alive, you need to do something to keep the service alive like a while loop.
@nikhilsachan_cse7144
@nikhilsachan_cse7144 Жыл бұрын
There is no code for stopping foreground service
@cosovic14
@cosovic14 2 жыл бұрын
Is there a way to have a foreground service without a notification ?
@Codeible
@Codeible 2 жыл бұрын
No, you need ir.
@harleenkaurarora1817
@harleenkaurarora1817 2 жыл бұрын
If phone is idle mode background service is not working. How to do this??
@Codeible
@Codeible 2 жыл бұрын
You need to use foreground service.
@harleenarora5189
@harleenarora5189 2 жыл бұрын
@@Codeible Example you have provided is with foreground service only right?
@Codeible
@Codeible 2 жыл бұрын
@@harleenarora5189 Both Foreground and Background.
@gianmarioorru1808
@gianmarioorru1808 2 жыл бұрын
the app works fine in the background, but if I want to use it in the foreground it crashes after about 7 seconds. I don't know why
@onuralagoz6531
@onuralagoz6531 Жыл бұрын
Use wake lock with no time limit to make foreground service work infinitely. But never forget that unnecessary amount of foreground service usage is a real battery killer
@Nick-cx4rs
@Nick-cx4rs Жыл бұрын
Yo how this receiver working really we didnt even set registerReceiver()
@pankajlagad3291
@pankajlagad3291 2 жыл бұрын
How to keep running the service even we kill the app ?
@Codeible
@Codeible 2 жыл бұрын
Create a foreground service - 3:43 If you want to restart the service automatically, create a broadcast receiver - 11:12
@dfged9654
@dfged9654 Жыл бұрын
kzfaq.info/get/bejne/mKdnqZSGx9DQqqs.html Here, the service is stopped. But the service is not explicitly stopped by calling stopService() or stopSelf() from within the service itself or by another component such as an activity or a broadcast receiver. I wonder why? Thx :)
@pewienktos1292
@pewienktos1292 2 жыл бұрын
n1
@shafiqsadat37
@shafiqsadat37 2 жыл бұрын
@VoxLott
@VoxLott Жыл бұрын
Why so many ads dude? I watched sum of 1.5 mins ads whole through this video
@imadsaddik
@imadsaddik Жыл бұрын
Thanks
@mdottech6502
@mdottech6502 2 жыл бұрын
Awesome
@samiulalim1230
@samiulalim1230 Жыл бұрын
Normally the codes working fine but when i add a webview in main activity then foground service stopped when apk closed. Is there any solution for it. I want to keep webview in my project and also want the foreground service
@Codeible
@Codeible Жыл бұрын
Hi, should still work.
@samiulalim1230
@samiulalim1230 Жыл бұрын
@@Codeible not working after adding webview 😭😭
Bound Services on Android
43:00
CodingWithMitch
Рет қаралды 61 М.
Фоновая работа в Android: Service и WorkManager // Курс «Android Developer. Professional»
1:41:26
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 26 МЛН
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 49 МЛН
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 86 М.
Write Laravel, not PHP (feat. Aaron Francis) | 029
58:45
Backend Banter
Рет қаралды 14 М.
Understanding and Using Services in Kotlin - Beginner
16:08
Android Geek
Рет қаралды 11 М.
Digging Into Android System Services
31:58
Dave Smith
Рет қаралды 32 М.
Building a Mobile App in 2024: The BEST Technologies
13:31
Dan Ilies
Рет қаралды 5 М.
How to Hide & Protect API Keys in Your Android App (Reverse Engineering)
10:13
Full Guide to Delegation in Kotlin  - Android Studio Tutorial
18:10
Philipp Lackner
Рет қаралды 67 М.