This course will be retired on June 1, 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
Start a free Courses trial
to watch this video
There are lots of ways to work with the web in Android. One of the easiest and most robust is a 3rd party library called OkHttp.
Related Links
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
As one might expect,
0:00
there are many different ways to
interact with the web in Android.
0:01
The Android ASDK has some
APIs that we can use.
0:05
Also, because it's such a common task,
0:09
many different third party
solutions are available.
0:12
By third party solutions,
I mean solutions written by developers
0:15
that are not part of
the Android ASDK itself.
0:19
Why would someone write their own API?
0:22
Well, the reason there are so
many third party solutions is that working
0:26
with HTTP and WebRequest can be
a little painful with the Android APIs.
0:30
For many situations, the solutions
provided in the Android SDK are great.
0:36
Sometimes, however,
better solutions are available.
0:42
We can think of third-party libraries
like upgrades to a bicycle.
0:46
I'm sure that your last bicycle came with,
for example, a fully functioning seat.
0:50
However, you might have found it to
be slightly uncomfortable to use for
0:56
a long period of time.
1:00
Using a third party seat can help make
the experience much more comfortable.
1:02
I'm here to help you become
a great Android developer.
1:06
Sometimes, that means using
third party libraries to make
1:10
our development experience more
comfortable than it would be when strictly
1:13
adhering to the official SDK.
1:16
How does one get started when doing
something new in programming?
1:19
A great first step is to check for
resources and see what's available and
1:23
recommended.
1:27
Now, I know you didn't come
here to watch me Google things.
1:28
You want to learn how to be a developer.
1:31
Well, here's a secret, okay?
1:34
Don't tell anyone.
1:37
Developers use Google all the time.
1:38
Using the web to help solve problems
allows you to avoid common pitfalls and
1:42
to reuse solutions from other developers.
1:47
But what do we need to search for?
1:51
Let's start at the Android
developers site.
1:52
Go over here to Develop and guides.
1:56
Scroll down a little ways
until we find Connectivity.
2:02
So Connectivity's what we're looking for.
2:07
Well, there's not a ton of great
information here on the developer site for
2:09
HTTP connectivity.
2:14
I know there has to be some
great solutions available.
2:17
Let's head back over to Google and
2:20
search for the best Android HTTP library.
2:24
We get our results here with the better
options at the top of the page.
2:30
When doing these searches,
pay attention to dates on the articles.
2:34
Things in Android, and
technology in general, change quickly.
2:38
So something from 2015 may be outdated or
unsupported.
2:42
We can restrict our search
to a specified date range.
2:47
Go to Tools.
2:50
Here, where it says Any time,
choose within the past year.
2:52
We see that there is a mention
of a few different libraries.
2:58
Now, here's a great tip for
searching to compare items.
3:01
This works for almost everything when
investigating different products.
3:05
Search for its name plus these
two magic letters, VS for versus.
3:09
Let's search for Android Volley.
3:14
Android volley versus, auto-complete
in the search bar shows some common
3:20
libraries that are compared
to one another.
3:25
Now, I know from past experience
that this library here,
3:28
okayhttp, is very easy to work with.
3:32
And it's what we'll use for
our Stormy app.
3:36
Now, you might be thinking this is great,
Ken.
3:38
You've been here before, so
this is going super smoothly.
3:41
You're right.
3:45
Sometimes research can
be super frustrating and
3:46
take up way more time than you thought.
3:48
Trust me, though, researching options is
helpful and makes you a better developer.
3:51
Let's Google okhttp library.
3:56
We'll see that we can get it from GitHub.
4:07
This library is provided
by the company Square,
4:13
which has contributed many different
libraries to Android development.
4:16
It's under active development, and if we
scroll down a bit to view the Read Me
4:21
section, we see some information
about how to use the project.
4:25
An important spot to check when looking at
third party libraries is for the license.
4:31
OkHTTP is released under
the Apache license,
4:41
which means it is open source and
free for us to use.
4:44
Okay, I know you're taking this course
to learn how to be a developer.
4:48
And I'm saying to use
code from someone else.
4:52
Isn't that cheating?
4:55
Not at all.
4:56
Making use of third party solutions
4:57
is a great way to be a more
productive developer.
5:00
Popular libraries such as
these are well tested.
5:04
Look around in this repository a bit
to see how much code it takes to get
5:07
HTTP connectivity working properly.
5:11
It's a great option to use.
5:14
Back in the readme file,
5:16
it shows us how to include OkHttp
in our Stormy project with Gradle.
5:17
Let's see how to do that
after a short break.
5:23
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