Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
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.
Let's start by opening the Android device monitor.
And then running our app.
Then let's find our app in the list on the left
click it, and then click up here to show our app's threads
Notice that this time our downloadThread already exists because we now create
it in the on create method instead of when we click the download button.
Now let's click the download button and watch our song start to download.
After ten seconds we can see them start downloading in the log messages below.
And another ten we get another song.
But now with our app still selected let's click this stop sign up here
to kill our process.
Immediately we can see that the app is no longer running and
if we give it a few seconds we can tell that our download thread has stopped too.
No more log messages.
Now I know what you're thinking, this isn't that surprising.
You killed the app, but of course everything stopped.
But it didn't have to be that way since processes are routinely kiln
to free up resources, Android provides us with a way of dealing with this and
that way is services.
You need to sign up for Treehouse in order to download course files.Sign up