Bound Services on Android

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when it comes to services on Android you basically have two categories started services and bound services in this video I'm going to talk about bound services one you want to use a bound service and then we'll do an example of how to set up a bound service and use it in your projects also I'm gonna be using the architectural design pattern known as model view viewmodel otherwise known as mvvm mvvm is my favorite design pattern so I'm trying to use it more and more in my videos whenever I can for those of you who are unfamiliar with services on Android here's a quick overview of what they are and typically what they're used for a service is an application component that can perform long-running operations in the background with no user interface the no user interface part is extremely important that means you can leverage services to execute long-running operations without displaying anything on the screen so if the application is sent to the background you could design a service to continue running even though the app is not visible to the user that brings me to the next property of services they have their own lifecycle independent of the activity or the fragment that they're created in essentially this is the property that gives services the ability to continue running even if the application is not visible to the user by default services are unaffected by activity or fragment lifecycle events such as on destroy on pause and so on here's some of the things that you need to watch out for when using services in your projects by default services do not run on a background thread this is a very common misconception but I totally understand why people often get confused by this the Android documentation describes services like this a services is an application component that can perform long-running operations in the background with no user interface the part that says in the background could easily be interpreted as a background thread but that is definitely not the case by default services operate on the same thread that they're instantiated on in most cases that's going to be the main thread if you're interested in this topic leave a comment below and if there's enough interest overall that I'm gonna do a video on it but this video is focused on services that do not run on background threads or don't have threads running in them it's just a plain old service the second thing that you need to watch out for is how to determine which type of service to use there's a few types there's bound services and they're started services now this can get a little confusing so pay close attention to what I say here technically a bound service can also be a started service but a started service cannot be a bound service I'm going to talk more about this in the application demo but essentially a started service is started up by calling start service or start foreground service a bound service on the other hand can start two different ways it can start when some other component binds to it so the literal act of something binding to it will start the service or you could start the service using start service or start foreground service and then bind to it both work but have slightly different properties like I said I'm going to talk more about this in the demo ahead now that you've had a short review on services I'm sure you're wondering what exactly is a bound service and why should you care about them 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 a client at its core you're defining a client-server interaction the service acts as a server and some other component acts as a client the client could be an activity it could be a fragment it could be a SmartWatch or it could be some other application completely different so why should you care about bound services personally I like to use bound services when I know there's going to be some kind of consistent or frequent communication between an activity and the service or a fragment and the service whatever same thing like if a service is streaming music for example information like the playback progress needs to be constantly sent to the activity or the fragment so that way the user knows what's going on think about the seekbar imagine when you're watching a video or your streaming audio you're always watching that seekbar that seekbar data is coming from a service and getting sent to an activity or a fragment in a nutshell that's with a real advantage of using a bound service lies when you need to communicate with it on a consistent basis by binding to it you can communicate with a service very easily all right let's do an application demo here's the app that we're going to be building in the course it's a very simple app with a service a background service that's supposed to mimic what it's like to be running a long-running task or some kind of a some kind of an operation that takes a long time so if I press the button that says restart the service is restarted that progress is restarted and if I press Start it starts a runnable in the background to mimic what it's like to run a long-running task as you can see I just pressed pause there which then pauses the interaction and if I press start again it runs to completion and then I can restart the whole thing if I want to so what's happening here is when the activity first starts when the activity first comes into view it's starting a service and then it's binding to that service then when I press the start button its initiating a runnable that exists in the service that runs until completion because it's a bound service I can very easily communicate with the service by pressing pause or start or pause or start and just I can just continuously do that with no issues because the activity is bound to the service so it communicates very efficiently with the service and this demo application is built using mvvm the architectural design pattern which as you probably know is my favorite architectural design pattern I wanted to give more more I want to give more examples of mvvm so I thought this was this was definitely a good one to do if you're not familiar with mvvm or model view viewmodel you might want to check out my blog post or my video on my youtube channel about mvvm that's going to give you a better starting point so you'll be ready to tackle this video before we start with the example I just wanted to show you where you can get a reference to the code that I'm going to be using in the demo so you can go to my github page and go to bound services with mvvm you can see the URL up here and if you ever get stuck just grab grab the master branch and you can take a look at the code here and compare it with yours just to make sure that you got everything right other than that let's get started with the demo okay so the first thing I want to talk about is the build up Gradle app file and the dependencies we're using mvvm the architectural design pattern known as model view viewmodel so we need to get the lifecycle dependencies that I have down here you can see them and I'm using the 1.1.1 version okay so next let's talk about the layout file if I open up activity main here I have a pretty simple layout I just have a relative layout with a progress bar a textview and a button so you can see on the screen at the progress bar the textview and the button pretty pretty straightforward nothing too exciting here then if we go into main activity the only components that I've defined already are the progress bar the textview and the button I've attached them to their IDs down here and I've attached an onclick listener to the button that's all other than that we're going to be building everything from scratch okay so to start off we're going to be building the service class so I'm going to right click on the main package directory gonna go to new Java class and I'm gonna call it my service I'm going to extend this class by service and you can see it's giving me a warning I'm gonna press alt enter and click on implement methods and insert the on bind method this is the only method that's required if you're using a service whoops obviously you'll probably end up putting more methods inside but this is the only one that's required to make that warning go away sorry the error go away you can see I'm also getting a warning up here telling me that this service is not registered in the manifest meaning that if I go into the manifest that service is not in here so I can either add it by pressing alt enter on here and going to add service to manifest or I could manually add it just by going service and then declaring it like that every service that you make in your Android projects must be declared in the manifest that's what it says in the documentation okay we're done in the manifest for now I'm going to go back to the service and start declaring some variables the first thing is a log for debugging the next thing we need to build is a custom class that extends binder and I'll write it out and then we'll talk about it so public class my extends the binder class and inside here I want to do my service get service so it's going to return a service object and I'm going to return a my service status so I'm essentially returning an instance of this service or some might call this a singleton it's a it's a reference of this service a reference to this service class so what is this binder thing the purpose of the my binder class is to provide an access point for retrieving a service instance the eye binder interface is the base interface used for a remote able object that probably sounded a little confusing so let me just kind of summarize that for you basically all you need to know about this is that it's used to get an instance of the service inside whatever you want to bind to it in the case of this example we're going to be binding to it using main activity so main activity will be the client and this service will be the server the my binder is going to help facilitate that binding or that connection between the activity and the service okay so now let's declare a bunch of other variables that we're going to need inside the service the first is going to be a binder object and I'm going to call it M binder and set it equal to my binder so notice that the my binder class is what we're using right here next is a handler object so handler M am handler we need a integer for the progress and we need a boolean so private boolean M is paused the purpose of this service is to simulate some kind of a long-running operation all I'm gonna do is use a runnable and handler to increment an integer value that integer value is going to be the m progress variable that you see right here and then the max value is going to be the maximum value that it gets incremented to once it reaches the max value then it will stop then obviously the M is paused boolean is going to be used to either pause that runnable or let that runnable continue running next I'm going to insert the oncreate method all services have an on create method this gets called when the service is first started so inside here is where we want to initialize our objects so I'll write new handler for Handler and I can write M progress equals zero M is paused equals true to start and Max value equals let's say 5,000 and since we have our binder object also return the binder right here this is how if I if I didn't mention it earlier this is how we're going to kind of facilitate the communication between main activity and the service what happens when we bind main activity to the service is it returns this M binder object and then we can use that to get a reference to the service inside main activity now I'm going to build the method for pretending to do that backward backward Libba simulating that background operation I'm going to call it public void start pretend long-running task so there's no questions as to what this does it's going to be pretending to do a long-running task and I'm going to just write it out and then we're going to talk about it because normally I can't talk very well when I'm trying to write these out so we're gonna use a runnable then inside the run method of the runnable we wanted to check if the progress is greater than or equal to the maximum value or it's paused if either of those conditions are met that means that we want to stop this runnable so I'll say we're moving callbacks and I want to remove the callbacks from the handler and then I'm gonna have a method for pausing so pause pretend [Music] long-running task I haven't created this method but I'm going to otherwise then we want to update the progress so M progress plus equals 100 so we're going to be incrementing the progress by 100 each time and then M Handler post delayed and I want to reference the runnable and then we want to do this same operation again in 100mm seconds that's why I'm passing 100 here and then of course you need to start this whole process so down here I need to call em handler post delayed and then reference the runnable and the time that it's going to post in so actually I think I did an okay job of explaining as I went there but let me just go through one more time so there's a runnable if the progress is greater than or equal to the maximum value or it's paused then we want to stop it and pause the long-running task otherwise we want to continue incrementing and then post again in 100 milliseconds so that's going to keep kind of looping this runnable over and over again until one of these conditions is met okay so now let's build a method for pausing one of us alt enter and create that method inside the service and inside here I just want to set the is paused boolean to true and that will effectively pause that runnable since we're checking constantly right here for if that's true next we need a method for starting this task or whoops starting this round oval so I'm going to create a new method private void let's say Sun pause I'll just copy this name actually because that way I don't have to write it out so I'm going to say unpause pretend long-running task and that means M is paused equals false and I want to start that long-running task now before we move on to the next part I just need to create a couple more methods that we're going to use to retrieve values from this service the first one is actually I'm not going to write them out because they're pretty basic so I'm just going to kind of I'm going to fast forward the video here and skip ahead to after I paste these in and then we're gonna talk about them okay so we have get is paused which returns the paused boolean get progress which returns the progress get max value which returns a max value and then reset task which sets the progress to zero and effectively resets that whole adult task I guess incrementing process or tasks the next method that we're going to build is a very important one so I'm going to press ctrl o and I'm going to search for a method name on tasks removed going to insert that so why is this method so important this method will be called when the application is removed from the recently used applications list I'll show you what I mean so here I have the demo app on the screen what I mean by the recently used applications list is if I minimize the app or I set it to the background this is the recently used applications list if I swipe this application out on tasks removed will be triggered so why is that important it's important because with bound services the service is going to continue running until the last client has unbound from the service so for example in in this app we have main activity binding to the service that means the service will not stop until main activity has unbound from the service but what we can do instead is to call stop self inside on tasks removed that way when the task is removed like I just demonstrated the service will stop stop self is like a hard stop for our service that way we don't have this service still running in the background even though the application has been closed because of course you don't want that you don't want the application to continue running even when it's been swiped out by the user that would not be a very good user experience there's no reason for the service or the application to continue running if the user closes it so that's it for our service here next we're going to work on the view model once again if you're not familiar with mvvm the architectural design pattern make sure to watch my video on mvvm it's on my youtube channel and that will kind of give you a good starting point so you know what I'm gonna be doing here because otherwise you're gonna have no idea so I'm gonna right-click on the main package directory go to new Java class and I'm going to call this main activity view model I'm going to extend this by view model and now we're ready to build the view model class first thing I need is a log for debugging so I'm just pressing log T there you can see I pressed log T and I pressed enter and it gives you that output right there next I'm going to create the variables that we need the first is a mutable live data object of type boolean and I'm going to call it m is progress updating the next object is a another mutable live data object when it's going to be of type my service dot my binder I'm going to call it M binder the reason I'm keeping a reference to the my binder object inside the view model is so I can easily monitor when the activity is bound to the service and one it is unbound typically you do this using a boolean but I can use the object since we're using mvvm next I'm going to create the two live data getter methods so live data and it's going to be of type boolean get is progress updating and return M is progress updating and then the second one is going to be another live data not mutable just live data that's gonna be my service dot my binder whoops and I'm gonna say get my binder sorry actually the source code all my github is get binder so I better keep that consistent in case any of you were checking with the code on github so you've probably noticed that I'm declaring the objects as mutable live data but I'm returning of type live data this is because live data objects cannot be directly changed there's no setter method so for example just if I was to insert a constructor here just for the sake of argument I don't need to have anything in here if I go if I was to change this to live data and go M is progress updating there's nothing to set the value there's only get value observers and observe but if I was to change this to a mutable then you can see I can set the value or post a value and that's how you actually trigger observers to trigger their own change method which we're going to look at later but once again this is probably going to be very confusing I'm kind of just going over the mvvm stuff really quickly because I have a video on YouTube that goes through it really slowly so if you're confused check that out alright next we're going to build a very important object when it comes to Bound services and the whole binding process it's going to be a service connection object I'm going to call it service connection equals new service connection and as you probably guessed from the name this is what's responsible for actually facilitating the the connection of the service to the the client which is the activity or the fragment or whatever whatever you're binding it to so the on service connected method will trigger when the client is bound to the service and the on service disconnected method will trigger when the client is unbound from the service the on service connected method returns a component named object and an eye binder object the component name will represent what service is it's being bound to that's why it's called the component name the eye binder is the link between the the client and the server so that's what's gonna help us to actually make that connection and I'll show you what I mean in a second here so first I'll write a log saying connected to service and then I'm going to go my service dot my binder binder equals my service stop my binder and then I binder and then we can actually connect by doing my binder dot post value and send that binder so technically I'm actually not connecting with this line of code but what this is going to do is it's going to send that binder object to the client where I can then make the connection and that probably sounds confusing but I promise it's gonna make sense just kind of bear with me for now I'm just kind of getting this class done and then we're going to work on main activity where you'll see the actual bind taking place so here we want to do the same thing but we want to pass a null because that means that the client has unbound from the service so we want to make the binder null okay time to work on main activity so I'm going to open main activity and the first thing I want to do is declare two new objects one is going to be the my service object and we call it M service and the second is going to be the viewmodel sameen activity viewmodel I'm gonna call it M view model as a side note some of you might be wondering why I didn't declare the service inside the view model and I just want you to know that I could have there's no real reason for or against it in this case I just didn't see any reason to add it we're not monitoring changes to the service we want to monitor changes to the values in the service so I don't see a reason to add it to the view model but you could have now I'm going to scroll down here and instantiate the view model so view model equals view model providers of then reference the context get and we want to reference our view model class so main activity view model class now it's time to actually start the service and bind to it if you recall from the introduction section of this video I said the second thing that you need to watch out for is how to determine which type of service to use there's bound services and started services then I went on to say technically a bound service can also be a started service but a started service cannot be a bound service this is where I'm going to explain all that in detail first I'll write the code for actually starting the service I'm going to insert the onresume method since that's what we're gonna actually want to start the service and now I'm gonna build that method for starting it so private void I'll call it start service and inside start service we need an intent that intent I'm going to call service intent since it's starting a service and it's gonna be new intent reference the context and then reference the my service class now just call start service and pass the service intent then we want to call that in on resume that way if the activity is paused or destroyed or whatever and it comes back on resume is going to be called and then that service is going to be restarted and yes I'm sure some of you are already wondering that means that we're going to want to stop the service and unbind it in on pause but we're going to we're going to get to that in a little bit so just hang on so right now the service is going to start but there's nothing that binds to the service right now it's just a plain old service and it's starting up nothing is binding to it so that's we're going to work on next we're gonna actually bind to the service so the next method I'm going to build is the bind service method some bind service and inside here it's going to be very similar so intent service intent equals new intent this I mean once again we have my service dog class but instead of calling start service I'm going to call bind service and then pass the service intent if we need to pass a service connection object as you can see we don't have that yet someone's going to pass a null and then we need to pass a flag so this flag is going to be bind Auto create meaning that the service will get created if it hasn't already when this activity or this client binds to it so how do we get this service connection object because you can see I passed null here well the service connection object is the one that's actually in our view model this service connection so we need a method to return it so you need public service connection get service connection and then return the service connection then we can use that in here just like that so we referenced the view model and then call get service connection now I'm gonna call bind service underneath start service and that will complete the starting of the service and then binding the service to the weight starting the service and then finding the activity to the service I should close this so we have more room now before we move on I just want to clarify a few things this is a bit confusing so listening closely as I said in the introduction there's two ways to start a service you can either start it using the start service or start foreground service methods which is what we did we use start service or you can bind to it then the literal act of binding to a service will start it for example if I didn't call the start service method or I didn't have one I could just call bind service inside on resume just like this so if I was to get rid of this and instead I just called bind service that would also start the service through the act of binding to it the only thing is there's a limitation with starting a service this way the service will only stay alive as long as something is bound to so as long as there's a client bound to it as soon as the client unbinds the service will be destroyed but if you start a service using the start service or start foreground service method then you bind to it like we've done then the service will stay alive even if all the clients are unbound so obviously depends on the situation but in this situation that's what we're going to do we're going to start the service and then we're going to bind to the service that way if for some reason the activity unbinds which there's basically no way that could happen but if it did happen then the service would still continue running even though there was nothing bound to it so during that explanation you might have heard me say something about a start foreground service method so you can see if I type start foreground service that's also a method that's available I could just pass a whoops a service intent to that and I'm see me to reference there the context if you do that it's also giving me an error saying yeah see it requires Android oh so this is the method that you want to start your service if you're using Android oh also if you want your service to run indefinitely but that's not the only step there was a there was a lot of changes made during Android oh you have to start the service using star foreground service and you also need to display a notification like a push notification while the service is running that's going to be outside the scope of this video but if you guys want to see more on services in Android oh and how you can use them and how you can run them indefinitely just leave a comment in this video and have enough people will show interest then I will definitely make a video on it okay so next is unbinding from the client because as i mentioned earlier if if we're calling start service in on resume we obviously want to unbind from the client in on pause otherwise you're going to get start service calling over and over again which which we don't want so in on pause I'm going to call if our view model target binder does not equal null meaning that the service is bound and it exists I want to unbind the service and do view model dot get service connection the way we have this set up the bind service method will be called which will then cause the on service connected method to be fired when main activity has connected you need a a reference you can just go in here this is the on service connected method that I'm talking about that's going to be fired when they when we call bind service inside main activity so when this method is called right here but we still haven't actually gotten a reference to the service we've bound to it but there's no reference being saved in main activity to that service so that's what we need to do next since I'm using mvvm I'm calling post value on the binder and then passing the binder after the connection is made so the question becomes how do we get a reference to this binder because that's what we need to get a reference to the service in main activity and the answer is we use an observer so once again this is an mvvm concept so if you need a refresher on mvvm make sure to watch my mvvm video on youtube so what I'm going to do is I'm going to write view model dot to get binder and I'm going to apply an observer so this new observer and that's going to give me a reference to that my binder object when it gets set in the view model so when it gets set right here or when it gets set right here that's going to trigger the on change method and this is how we get a reference to the service so if the my binder object does not equal null then I want to go M service equals my binder dot get service otherwise then we can just set the service to no because that means that we don't have a reference to that binder anymore or in other words it's been unbound just to be clear I could write some logs here for debugging saying connected to service and then down here I could say unbound from service so that's the basic setup for starting the service binding to it and unbinding from it now we're going to work on the logic for displaying the progress on the screen next we need a way to actually start the runnable or the long-running task in our service so we need to call this method right here so in main activity I'm going to create a new method named private void toggle updates and I'm going to call toggle updates inside the button when it's clicked so toggle up to so first we want to check if the services null because if it's null we don't want to call any methods on it that would cause the app to crash the first check I want to do is if the service get progress equals service get max value in that case that would mean it's finished we want to reset the task and do the button set text and set that to start otherwise if the service is paused okay it's paused then I want to unpause the service looks like I don't have an unpause method let me just go into the service here it looks like I made that private so I'm going to change these bolts of public now go unpause and I also want to do view model dot set is looks like I don't have a we need a setter method also in the view model for setting the is progress updating boolean so I can create that right now so public void set is updating that's going to take a boolean call it is updating so M is progress updating I want to do post value and set it to is updating now go back into main activity and do set is updating I want to set that to true since its unpause the task is unpause therefore it should be updating and then otherwise we want to go down into an else statement and say service dot pause for 10 long long running tasks and view model dot set is updating and we want to set that to false now the last part is going to be observing changes to that is progress updating boolean because that's going to determine what the button says on the screen because we have I don't have the app open that'll determine what this button says on the screen it needs to be updated and also the text here needs to be updated and the value here needs to be updated so since we're using mvvm I'm going to attach another observer so I'm going to get is progress updating set another observer this new observer now will be notified whenever that boolean has changed or in other words when the toggle updates method is called because down here we're changing it here and we're changing it here so when that's done this unchanged method is going to be called so I want to check if a boolean is true otherwise or in other words if it's updating so if it's updating then I want to do if the view model get binder getting value does not equal null so in other words if it's actually bound then if our service I'll get progress equals service get max value that means we're done so I mean Zen view model dot set is progress updating to false because that means it's finished then below that we want to set the progress so progress service get progress and progress bar dot set max to the maximum value so get max value then string progress this is for displaying in the text view equals string value of let's do a hundred to convert to percentage M service get progress we want to divide by M service dot get max value so that's going to display a percentage value in that text view so that's that's this value right here so I'm text view set text to that progress woops I need to add a percentage here too so add that percentage and then just progress but the way this is right now it's not really good enough because we need to be receiving updates constantly we can't just ask for an update when the status of this boolean has changed we need to be requesting updates to that progress constantly so I'm gonna use another handler here just like we did in the service class so equals new Handler and I'm going to use another runnable so final runnable runnable equals new runnable and I take this logic and put it inside oops inside here inside the else statement I want to do handler dot remove callbacks because that in that case the value has been reached or in other words the is updating boolean is now set to true I can make this final so that I can actually reference it inside there and so that's good and then right here we want to do Hendler dot post delayed post delayed reference the runnable and we want to check every 100 milliseconds so that's going to keep this runnable running and checking for the progress every 100 milliseconds and the last little bit of logic is going to be below our edible here we just need a bit of logic to handle what the what the text view says and what the button or sorry what the button says if it's not updating so M button set text to pause and we want to do Hendler got post delayed we will reference that runnable and check every 100 milliseconds otherwise we need to check if it's been completed so service this is the same kind of thing we just did inside the runnable equals service get max value meaning it's completed and in that case we want to do button set text to restart because our thing is completed our runnable is completed and last one else button set text to start so if the on changed method is triggered that means the is progress updating boolean has been changed and the first case is our runnable object here if the boolean is true meaning the updates are needed the updates are being made then we want to retrieve the progress from the service and continue looking for progress with the post delayed method if the boolean is false meaning the updates are no longer being made we want to remove the callbacks and stop checking for progress then down here we have if the progress updates are being made we want to set the text of the the button to say pause so I press start it needs to say pause and we want to look for updates with the post too late method otherwise if it's false we want to check to make sure it's not completed so the progress doesn't equal the value if it does equal the max value that means that this has reached the end and we should see the restart right here otherwise we want to see start so I click restart that means we want to see start right here so that's it that's that's generally all the logic so now I'm going to run it and we can test and make sure that everything is working as we expect all right so I'm going to press Start actually open the log here so we can take a look at the log output so I'm going to press start here see it starts I'll press pause if I move this over you can see that the progress is updating constantly after I press start if I press Start it continues pause again it'll stop stop you can see it says removing callbacks now I'm gonna let it finish so it ends you get 100% this changes to restart you can see the callbacks are removed now I'm going to restart it and I'm going to start it up again and I'm going to move the app to the background so I'm going to start it now when moved the app to the background you can see it's still going if I reopen the app it's still running just as if I was still having the app open now I'm going to try that one more time but I'm gonna actually exit the app so I'm gonna remove it from the recently used list so I'm gonna press Start I'm going to then swipe the app out and it stops so that's exactly what we expect that means that inside of our service class if you scroll down to the on task remove method that is effectively stopping the service which is exactly what we want so now you've seen a simple implementation of a bound service using mvvm I want to do a little summary just because we've covered a lot here so let's go into main activity and I want to just kind of walk through the whole process so the service is started in on resume by the start service method remember it's not started by the act of something binding to it it started by me calling start service and passing this intent after that I'm calling bind service and binding the activity to the service so here the activity is acting as a client and it's binding to the service which is acting as a server when bind service is called if we look in our view model the on service can did method will be fired at that point the binder gets a new value posted to it and if we go back into main activity we are observing changes to that binder so you can see view model get binder dot observe so when that binder is changed right here when the value is posted to it the service will be able to be instantiated so I can go service equals my binder dot get service and that's going to give me access to all the public methods that are inside the service so all of these public methods here just as a reminder so if I scroll down here if a service is started using the bind service method so if I if I didn't have this code right here if that was commented out that would mean that the service is sort of at the mercy of whatever clients are bound to it meaning it's starting by the literal act of something binding to it but it will also stop whenever everything is unbound from it but if I was to start the service like this which is what we did if I unbind from it it's still going to run just as another reminder I used the architectural design pattern known as mvvm in this video mvvm is my favorite design pattern because i think it's the best for most situations that you'll run into when developing apps if you're looking for a really prime example of why you should use mvvm i'll run this so i can give you a visual of what i'm talking about start this service let it run to whatever percent and then close the app so just kind of minimize it and go do something else play with another app for even hours and then come back to the app and reopen it and take a look at what it shows it's going to show the exact same thing as what it did when you closed it that's one of the most powerful things about mvvm it saves the state of whatever was in view and it will save it basically forever I don't think I'd ever will actually destroy it unless your phone runs out of resources somehow and the garbage collector cleans it up it will effectively stay in that state forever which is awesome I hope this video was helpful I know it's a little long but I want to make sure I got everything in here and explained everything thoroughly and I didn't skip anything or break up the video into pieces so if you came this far thanks for watching once again if you want to see a demonstration on how to start a foreground service using android oreo and above leave a comment in the comment section and if you want to see how to start a source for ground service that runs indefinitely and shows a notification also leave a comment in the comment section and as always thanks for watching you
Info
Channel: CodingWithMitch
Views: 38,759
Rating: 4.9188275 out of 5
Keywords: android tutorial, android services, android bound services, bound services android, bound service example android, android bound service example, how to setup a bound service android, what is a bound service android, services and mvvm, mvvm android, model view view-model android, how to use services on android, android services example, android services explained, bind service to activity, bind service to android example
Id: _xNkVNaC9AI
Channel Id: undefined
Length: 42min 59sec (2579 seconds)
Published: Tue Dec 11 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.