The Problem with Threads1:58 with Ben Deitch
In this video we see why we need to use Services!
We've learned the ton about threads, but now it's time we see why services exist. 0:00 Let's start by opening the Android device monitor. 0:06 And then running our app. 0:13 Then let's find our app in the list on the left 0:23 click it, and then click up here to show our app's threads 0:30 Notice that this time our downloadThread already exists because we now create 0:40 it in the on create method instead of when we click the download button. 0:45 Now let's click the download button and watch our song start to download. 0:50 After ten seconds we can see them start downloading in the log messages below. 1:02 And another ten we get another song. 1:11 But now with our app still selected let's click this stop sign up here 1:15 to kill our process. 1:21 Immediately we can see that the app is no longer running and 1:24 if we give it a few seconds we can tell that our download thread has stopped too. 1:28 No more log messages. 1:34 Now I know what you're thinking, this isn't that surprising. 1:37 You killed the app, but of course everything stopped. 1:41 But it didn't have to be that way since processes are routinely kiln 1:44 to free up resources, Android provides us with a way of dealing with this and 1:49 that way is services. 1:55
You need to sign up for Treehouse in order to download course files.Sign up