This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Video Player
00:00
00:00
00:00
- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
In this video we see why we need to use Services!
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
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 upYou need to sign up for Treehouse in order to set up Workspace
Sign up