Bound Services on Android

  Рет қаралды 61,946

CodingWithMitch

CodingWithMitch

Күн бұрын

With respect to Services on Android, you have two categories:
1) Started Services
2) and Bound Services
This video is focused on bound services.
I think the best way to think of a bound service is to compare it with a server. When you start a service with the intention to bind something to it, you essentially have the intention to start a server, and bind to it with some kind of client. At it's core, you're defining a client-server interaction. The service acts as the server, and an activity acts as the client.
Note that this demo is done using the architectural design pattern known as "Model View View-Model" (MVVM).
➤Blog post on Bound Services:
↻ codingwithmitch.com/blog/boun...
➤Learn to Code Like me:
↻ codingwithmitch.com/register/
➤My Instagram:
↻ / mitch.tabian
➤Source Code:
↻ github.com/mitchtabian/Bound-...

Пікірлер: 118
@cnsnmms3708
@cnsnmms3708 3 жыл бұрын
I was working on a ble sensor client service which must communicate consistently with an activity and I was almost hopeless because of the android os restrictions and started service logic. You are solving a very complex issue about android services with a such simple example :) thanks
@TechMalaya
@TechMalaya 4 жыл бұрын
I love ur tutorial when u explain it very simple to understand for me. Keep it going mitch. I just stuck using bound service in mvvm and u the only reference that I had.
@atifmbhutta
@atifmbhutta 4 жыл бұрын
Damnn Mitch you are the best. Precise and to the point. Very well explained videos always.
@satyamsharma8240
@satyamsharma8240 3 жыл бұрын
Love the way you made everything so simple
@alirzayucefaydal591
@alirzayucefaydal591 5 жыл бұрын
my mind blown :D i believe we need to go deeper and do more exercises with ur help :D
@trollrar
@trollrar 5 жыл бұрын
Background thread service tutorial please :)
@hassanruben1019
@hassanruben1019 3 жыл бұрын
Instablaster...
@kunalsahu4
@kunalsahu4 3 жыл бұрын
Thank you so much Mitch, that very cool explanation. I request you to please create more content on Services and running task in BG
@bjugdbjk
@bjugdbjk 5 жыл бұрын
Fabulous explanation, Thank you so much, Appreciate your efforts.
@muneerhasan
@muneerhasan 4 жыл бұрын
This video about service is best video on services. This video cleared my all doubt 💯💯. Thanks a lot Mitch
@virus2028
@virus2028 3 жыл бұрын
Good work, thanx for the lecture man. Helped a lot
@Priyanshu-nq8rm
@Priyanshu-nq8rm 10 ай бұрын
Thanks Mitch for an awesome tutorial ☺️
@shawngardner261
@shawngardner261 3 жыл бұрын
I enjoy your tutorials and classes. Wondering if you could update with foreground services and bringing in more clean architecture like less knowledge in the activity about the service, etc. Thanks!
@luvsinha1223
@luvsinha1223 3 жыл бұрын
awesome video. learned a lot .
@developerkang3717
@developerkang3717 3 жыл бұрын
this is exactly What i neeed!! Thank you from South korea
@user-hp2yi9yy3x
@user-hp2yi9yy3x Жыл бұрын
The best tutorial on services I ever seen
@mirkaram548
@mirkaram548 5 жыл бұрын
Make video on Starting service in ANDROID.O and changes in O. Your explanation is amazing with architectural design.
@davidfa7430
@davidfa7430 5 жыл бұрын
Thank you for your great video. I have a question that is it possible to given a service bound by multi-activities? so that no matter which activity is running, the service will keep running without re-create?
@nandandesai6524
@nandandesai6524 5 жыл бұрын
How can you run a service in a background thread? Please please make a video on it. Thanks!
@devanshu_on_youtube
@devanshu_on_youtube Жыл бұрын
Hey Mitch, love your tutorials! But if I may, isn't viewing a bound/started as service types (though not mutually exclusive) a bit inaccurate as a mental model? What exists is the Service class by itself - it can either be started, be started and bound to or be started as a consequence of being bound to. I think the folks have revised the documentation to reflect this representation as well.
@abdulwahid_mohammed
@abdulwahid_mohammed 5 жыл бұрын
That's so fantastic and useful.
@codingwithmitch
@codingwithmitch 5 жыл бұрын
I appreciate the love brother :D
@maheswaranmohan542
@maheswaranmohan542 4 жыл бұрын
Please make a video to cover all points including started service, foreground service, Run service in background thread.....and android O..... And how to choose the correct one....
@Since1059
@Since1059 4 жыл бұрын
Really Really Really so nice and clean directions about bind services 😘😘😘😘
@realtimeexperience4470
@realtimeexperience4470 4 жыл бұрын
your all videos are awesome. Can you make a complete video/split in series which has all the folder structure.. where to keep UI/ViewModel/Data/DB/Network with MVVM best practice.
@medicalpump9275
@medicalpump9275 4 жыл бұрын
Dude you are awesome...
@AnkurJagani1000
@AnkurJagani1000 5 жыл бұрын
That will be great if you can make video on startForegroundServices which is must for Android O devices.
@carlosalvarez2506
@carlosalvarez2506 4 жыл бұрын
Thanks for the video, it was really helpfull
@eureka4498
@eureka4498 3 жыл бұрын
Great leacture about service. In a bound service, I want to implement the never-ending sevice after booting the smartphone. I know that case in a started service but I don't have any clues in the bound one. Could you give me some comments?
@maysal-reem6457
@maysal-reem6457 3 жыл бұрын
Great video! And could you please make some videos about the whole services thing because it's confusing
@021ritvik
@021ritvik 4 жыл бұрын
Best tutorial ever!
@mohamadnabikazemi6737
@mohamadnabikazemi6737 3 жыл бұрын
perfect , thank you
@Androidmeda
@Androidmeda 5 жыл бұрын
Really thanks for this lecture, sir. could I ask you, when to use Service, when to use IntentService, when to use JobIntentService?
@ChrisAthanas
@ChrisAthanas 3 жыл бұрын
Some engagement getting you to 100k
@aminamer5283
@aminamer5283 5 жыл бұрын
thank you Mitch... another great video! made ma day ?
@amitabhsarkar9571
@amitabhsarkar9571 4 жыл бұрын
Please make a tutorial of forgroundService for android O.
@raveen1742
@raveen1742 3 жыл бұрын
I would love to see a service running in the background .... please make a video on it
@capitalcouch5095
@capitalcouch5095 5 жыл бұрын
Hey Mitch, Great Stuff. Your content has helped me a lot in learning Android. I am starting to do videos on Android as well. I was checking your older videos, a huge improvement in video quality over time. What kind of screen recording software are you using? Thanks :)
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Hey, it's camtasia.
@codingwithmitch
@codingwithmitch 5 жыл бұрын
What kind of videos will you be making? Like what topics?
@capitalcouch5095
@capitalcouch5095 5 жыл бұрын
I will start with general beginners Android topics. It seems these get the most views, to get the attraction. Eventually, stuff like building clone apps, or in-depth on a certain topic. You have some recommendation?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
@@capitalcouch5095 if you are looking to maximize attention then definitely beginner stuff. The unfortunate thing about that is it gets very boring lol
@capitalcouch5095
@capitalcouch5095 5 жыл бұрын
Haha, well no pain no subs gain. Actually, I haven't seen many videos on beginners stuff but digging down in the implementation details inside android framework. What can we expect on this channel for the next year?
@amremam8937
@amremam8937 3 жыл бұрын
I would be great if you have added an example of aidl in this video
@ant4197
@ant4197 5 жыл бұрын
what was the real use case of services like that? in your experience. looks quite difficult to understand if learning it on your own...
@HydroHeiperGen
@HydroHeiperGen 5 жыл бұрын
@CodingWithMitch Atfrist, thank you for offering so much of your time to help noobs like me. Your Video is pretty good, but as a experienced Beginner, there are some questions left open. @25.40 As I understood the point of MVVM is to encapsulate the way of getting Data and the displaying of Data, to create a better structured code. So why do we bind the Service to the Activity and pass the ViewModel class instead of starting the Service in the Activity, but bind the service directly to the VM.class? As I understand, in your video, we create a bridge from Service to Activity, which continuous to the VM and the data later on will be send from the VM to the Activity. Can you tell me where I went wrong?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
This is actually an anti-pattern btw. You shouldn't bind services like this. Check out this article medium.com/androiddevelopers/viewmodels-and-livedata-patterns-antipatterns-21efaef74a54
@olegalekos2181
@olegalekos2181 4 жыл бұрын
I have a guestion.. Let say i want my app to run a service that uses Sensor and calculates Steps and than return each step to Activity. A. Should it be On another Thread so it wont freeze main thread? B. Should it be Bound ?
@dineshchoudhary8221
@dineshchoudhary8221 5 жыл бұрын
Yes please do a video on running services in a background thread
@codingwithmitch
@codingwithmitch 5 жыл бұрын
noted
@figoaranta3505
@figoaranta3505 2 жыл бұрын
Hi Mitch, I am new in android development, where do you think is better to access a service, from view or ViewModel? Thanks
@shubamvirdi2907
@shubamvirdi2907 4 жыл бұрын
Sir please make a video of integrating exoplayer using services and getting realtime feed from the service of running music.
@timbraasch1514
@timbraasch1514 4 жыл бұрын
the MVVM pattern sure is a good pattern, but i wouldnt recommend using it in a guide video since it can confuse newer programmers.
@nishantkumar-fl3cy
@nishantkumar-fl3cy 4 жыл бұрын
Please make a video on what can we do on background service thread.
@ishankhandelwal741
@ishankhandelwal741 2 жыл бұрын
Awesome
@ravikumarmohan1415
@ravikumarmohan1415 4 жыл бұрын
Please make a tutorial of forgroundService for android O and also on WorkManager and AlaramManager with broadcast
@shyam8999
@shyam8999 5 жыл бұрын
Nice work and please create a video for android oreo background services and background location
@nktkumar82
@nktkumar82 3 жыл бұрын
This is awesome.Just had one doubt. Is it not wrong to implement the "Service Connection" inside ViewModel as it is against the concept of MVVM as ViewModel should not contain anything related to Android Framework or android framework apis.
@devanshu_on_youtube
@devanshu_on_youtube Жыл бұрын
That is the ideal case, but I think it's more of a KMM perspective, i.e. if you're targeting multiple platforms like iOS and Android using KMM, it makes sense to encapsulate all business logic in the view-model minus the Android Framework-specific stuff.
@wawa3
@wawa3 3 жыл бұрын
Wouldn't new handler and runnable be created every time the progressUpdating get onChanged this way?
@aliakkawi4759
@aliakkawi4759 5 жыл бұрын
Thanks a lot. What is the difference between Services and Android Job Scheduler? and when to use each? In one of my projects I used Android Job Scheduler to Schedule Push notifications twice a day. Thanks
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Too much to say about that. You should just read internet articles. I don't have a post on the differences.
@mimrankhan9974
@mimrankhan9974 5 жыл бұрын
please make a video on threads with practical example not just print log messages
@TropicalCoder
@TropicalCoder 4 жыл бұрын
I would like to have seen the service callback with progress reports rather than MainActivity polling for progress.
@szymek16s
@szymek16s Жыл бұрын
Great tutorial, I looking for solution of my problem and it's hard. I have an app which counting work time but when user closed app by accident I want that my time will be still counting cous of the service and whats happend that viewmodel updating view all the time in the same time ForegroundService do the same and my timer shows wrong value.
@IxIAlanIxI
@IxIAlanIxI 5 жыл бұрын
This was the best tutorial I found on the internet about Bound Services, but the fact that it uses MVVM is driving me crazy, because I can not rewrite my whole project to implement MVVM. Does anyone have a version of this code that does not use MVVM? I watched the video about MVVM to try to "remove" it from the code, but unfortunately I could only get my code to stop working.
@rizwansayyed7893
@rizwansayyed7893 4 жыл бұрын
No problem just write service binder instance or create service connection in directly activity meaning remove viewmodel and write service code in mai activity which is in viewmodel
@guillermoperez8250
@guillermoperez8250 3 жыл бұрын
Cool stuff, thank you. You can get a reference to the service as soon as you bind to it, no need for the observer. Just do: MyService.LocalBinder binder = (MyService.LocalBinder) service; mService = binder.getService();
@jacekgawel
@jacekgawel 4 жыл бұрын
Awesome tutorials.. but It is only for simple Services. What when I have a location service which returns ? I can do all that stuff like "calculate distance" "find speed" "change to LatLng" in service and do some getters methods but I thing it isn't right according to mvvm pattern. So I need to observe data in Repository somehow? There is a simple solution for this? Obviously I can get location from bounded service to activity, like you did, then viewmodel.setvalue(location). From viewmodel send to Repository, do the staff, and observe it, but it isn't right, isn't it?
@prafulnayak1
@prafulnayak1 4 жыл бұрын
It is a great tutorial. Can you please make a tutorial for Services for Android O or higher
@moammarqaddafi4858
@moammarqaddafi4858 Жыл бұрын
did you make a video to run service on bg thread?
@ankitrajdwivedi996
@ankitrajdwivedi996 5 жыл бұрын
Yes we need video on background thread
@codingwithmitch
@codingwithmitch 5 жыл бұрын
noted
@jinothomas8365
@jinothomas8365 4 жыл бұрын
@@codingwithmitch link?
@sukhwantsingh501
@sukhwantsingh501 4 жыл бұрын
Great sir.. please share on intent service
@pawankhandalnasirda
@pawankhandalnasirda Жыл бұрын
hey i am intested in the to run the service on background thread.
@amirhusseinpoudineh770
@amirhusseinpoudineh770 4 ай бұрын
Hi Mitch Please answer this ,i want to make a call waiting app , and i want to post a notification when some one call the phone , I did it using Broad Cast Receiver but i want to do it when app is completely close . is this video what i need ?
@chiragprajapati3989
@chiragprajapati3989 5 жыл бұрын
nice please make more video on service
@smit9779
@smit9779 5 жыл бұрын
Great tutor
@ramakrishnap5732
@ramakrishnap5732 4 жыл бұрын
how to run activity in the background in the android
@TheMikkelet
@TheMikkelet 3 жыл бұрын
I do not understand this example, Mitch. I tried downloading the repo and run it. The app doesnt maintain state. There's no notification, like you'd see in a media app, and the app resets the timer if you swipe to close. What is the point of a service exactly? Because it doesn't seem to hold any persistent state
@ofir-bar-softr
@ofir-bar-softr 4 жыл бұрын
Please make a background thread video :)
@shoaibmalik9934
@shoaibmalik9934 Жыл бұрын
How does the whatsapp show there call ui when someone calls
@deeprajpandey7612
@deeprajpandey7612 5 жыл бұрын
please make a video on background thread
@ryszardmachmudow9175
@ryszardmachmudow9175 2 жыл бұрын
I read ViewModel should not contain services, because Service has it's own lifecycle. Service field will lead to context leak.
@aleksamatic9558
@aleksamatic9558 4 жыл бұрын
what is your favorite architectural design pattern xD?
@notsure1516
@notsure1516 5 жыл бұрын
big Mitch
@gofudgeyourselves9024
@gofudgeyourselves9024 5 жыл бұрын
What are your thoughts on flutter? Will it replace native Android Development
@codingwithmitch
@codingwithmitch 5 жыл бұрын
I'm honestly not sure. I don't know enough about Flutter.
@sourovkarmakar3237
@sourovkarmakar3237 4 жыл бұрын
can you please make a video on media code API of android
@low_samba
@low_samba 3 жыл бұрын
sending message to a Handler on a dead thread java.lang.IllegalStateException: Handler (android.os.Handler) {2f8aa543} sending message to a Handler on a dead thread not work
@juanpusongjr.3102
@juanpusongjr.3102 5 жыл бұрын
awesome tutorial.. can you please give a clue how to integrate this on playing an audio.. thanks
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Boom codingwithmitch.com/courses/android-audio-streaming/
@thesalehmahmood
@thesalehmahmood 5 жыл бұрын
Haven't watched it yet but Is this video part of that Spotify alike app?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Nope just bound services
@ayeshazakria2215
@ayeshazakria2215 3 жыл бұрын
pls use microphones for clear voice. thanks
@giannisfragoulis3094
@giannisfragoulis3094 3 жыл бұрын
Make a video for infinite running servicee PLEASE
@tehleelmir4407
@tehleelmir4407 2 жыл бұрын
If you could have just explained in a simple video, what bound service is and how to implemented it that would have been much nice, using a simple example this video could have been much better and also lesser in time and code. Just like coding in flow. But still thanks :)
@pembatamang8233
@pembatamang8233 5 жыл бұрын
I put a log under aBoolean in the MainActivity and after the work is over, the aBoolean keeps changing. Why is it happening??
@codingwithmitch
@codingwithmitch 5 жыл бұрын
It's supposed to. That means the work is done
@pembatamang8233
@pembatamang8233 5 жыл бұрын
@@codingwithmitch I don't understand.... the river of true false true false kept going on in my log...is that how it works?? isn't it bad for performance.?? please explain a bit more
@codingwithmitch
@codingwithmitch 5 жыл бұрын
@@pembatamang8233 It's the runnable. It's constantly asking the service for updates. Every 100 ms. So if you put a log there, you'll see it run constantly.
@pembatamang8233
@pembatamang8233 5 жыл бұрын
@@codingwithmitchok... how do i stop it when the work is done??
@codingwithmitch
@codingwithmitch 5 жыл бұрын
@@pembatamang8233 Whoops. There was a bug. Good find. Inside the "run" method you can't use "aBoolean" because then it's final. Which defeats the purpose because it will never change. Use "mViewModel.getIsProgressUpdating().getValue()" instead of "aBoolean" inside the run method. gist.github.com/mitchtabian/0621da267a677cabcd1f270e3c6513fa
@arhamcodes
@arhamcodes 5 жыл бұрын
Please do a video on background thread.
@samuelorji8396
@samuelorji8396 5 жыл бұрын
checkout his course on Threads, It's on his website and on pluralsight also... It's pretty cool
@codingwithmitch
@codingwithmitch 5 жыл бұрын
thanks I noted your response
@codingwithmitch
@codingwithmitch 5 жыл бұрын
******************** WARNING: BUG ************************ Thanks to @Pemba Tamang for finding this bug. Inside the "run" method of the runnable inside MainActivity, change the "aBoolean" variable to "mViewModel.getIsProgressUpdating().getValue()". If you don't do this then the runnable will continue running forever and spawning new instances. It's due to the "aBoolean" variable being final and then being used to control whether the runnable runs or not. If it's final, it will never change. So obviously the runnable will continue running forever. Here is a gist with the updated run method: gist.github.com/mitchtabian/0621da267a677cabcd1f270e3c6513fa
@pembatamang8233
@pembatamang8233 5 жыл бұрын
its Tamang
@VonUndZuCaesar
@VonUndZuCaesar 4 жыл бұрын
Better: Use AndroidX WorkManager from the new Android Jetpack Library
@vennamprasad
@vennamprasad Жыл бұрын
please do video
@talatkuyuk6556
@talatkuyuk6556 3 жыл бұрын
Very nice tutorial. But as far as I understand, two separate runnable run at the same time in the activity and in the service to show the progress. It could be better, one runnable runs at the service and inform the progress to the activity via broadcast-broastreceiver or LiveData implementation in connection with viewmodel.
@amirs6472
@amirs6472 4 жыл бұрын
Please make a video on what can we do on background service thread.
Memory Leaks on Android
18:36
CodingWithMitch
Рет қаралды 56 М.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 36 М.
MISS CIRCLE STUDENTS BULLY ME!
00:12
Andreas Eskander
Рет қаралды 20 МЛН
Они так быстро убрались!
01:00
Аришнев
Рет қаралды 2,3 МЛН
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 25 М.
Фоновая работа в Android: Service и WorkManager // Курс «Android Developer. Professional»
1:41:26
DO NOT do this in a Software Engineering Interview
7:59
CodingWithMitch
Рет қаралды 9 М.
MVVM and LiveData on Android
10:41
CodingWithMitch
Рет қаралды 36 М.
Deep Dive into Android IPC/Binder Framework
54:57
InfoQ
Рет қаралды 60 М.
iOS Development is Easier than Android Development (VLOG)
20:41
CodingWithMitch
Рет қаралды 52 М.
Digging Into Android System Services
31:58
Dave Smith
Рет қаралды 32 М.
Digging Into Android Startup
1:00:07
Dave Smith
Рет қаралды 39 М.