In this section, we're going to create an
app to process an RSS feed, then display
the data on the phone or tablet screen.
Now in the process, we're going to be
looking at the following. So we're going to be
downloading data over the Internet.
We're going to be running tasks in the
background using an AsyncTask, and we're
also going to discuss why you should
actually avoid using AsyncTasks in
Kotlin. Next we're going to be parsing
XML to extract data from a downloaded
feed, and we're going to be using the
ListView widget for displaying a
scrollable list of items, and we'll
be getting familiar with adapters for
providing data to ListViews and also
other objects. And we're also going to
see how to create our own CustomAdapter.
Context is something we're going to be
talking about: what that is, what they are
and why we need them. And then finally,
we're going to be creating a menu for our app.
Ok, so RSS stands for Rich Site Summary
or Really Simple Syndication, but neither
of those are particularly descriptive,
and the term RSS is probably more
informative these days. So RSS is a way
to present web data in a standard format,
so that users can subscribe to the RSS
feed and receive updates automatically.
Now data isn't pushed out from other
websites, though. It's the responsibility
of the feed reader program to monitor
the site and pull down updated
information, as it changes. So we're gonna
start off now by having a look at an
RSS feed. Now if you haven't seen them
before, they're actually very common. Now
you can find RSS feeds on just about any
subject you care to think of, by searching
online. And, in fact, we're going to do
just that. We're going to switch over
now to a browser. In fact, we're going to
do that now and I've got my browser open.
So I'm going to do a search for Apple
RSS feed, and the first result that comes
up here is for Apple.com slash RSS, or
depending on your country, it might also
have the country. In my case, it's got
slash AU. But in any event, I'm going to
click on that, and that actually gives us
a list of all the public RSS feeds that
Apple maintain. Now there's a lot of
feeds with information from the iTunes
Store, so you can get lists of the top 10,
or 25, songs or albums, and the top apps -
both paid and free - as well as
information on movies and TV programs.
And as you can see, there's even
information that you can get on the
latest press releases; news that might be
of interest to developers and even
documentation. Now keep in mind that the
RSS itself is not the full information.
It generally contains a summary, and was
intended as a way to get notifications
of changes, to the content of sites that
you might be interested in, without
having to keep visiting the sites in
your browser to see if something's
changed. Now we're going to be working
with the top 10 free apps - that's this
link, this RSS feed over here. But once
you've got the app working with that,
you'll actually be able to modify it to
use any of these feeds you can see, or in
fact, any RSS feed you want, anywhere on
the Internet. So the app that we're
going to be creating in this section of
the course, is going to read the data
from the top 10 free apps feed. It'll
then decipher the contents, so that we
can display selected bits of the
information on the screen.
So let's actually have a look at the
contents, to see what we're going to be
working with. So I'm going to click on
the top 10 free apps link here, and the
feed will load in the browser. Now if
you're using Google's Chrome browser, as
I'm using here, you can see that it shows
raw XML rather than a formatted display.
What I'm also going to do, though, is start up
Firefox. I want to show you what the
equivalent thing looks like in Firefox
as well. We'll just go back to chrome
initially and I'll get the URL, then
we'll paste it into Firefox. Now you can see
that Firefox, on the other hand, is giving
us some more formatted view of the same
output. So in other words, it's got sort
of a built in RSS feed program, that can
take the XML that we saw over here, in
Google Chrome, and converted it to
something that's a bit more readable. And
that's because Google's Chrome browser
hasn't got a feed reader built in,
although you can download a plugin if
you want. But you don't need to worry at
this stage, because it's the raw XML that,
ultimately, we want to look at anyway.
So, as you can see, I've got the RSS feed
rendered in Firefox here, to
display the information that starts with
the title, at the top here; iTunes
Store: Top Free Apps. And below that, down
here, there's a series of entries - each
one starting with a title, the day it
was updated, as well as a summary of what
the app does. So let's just go back to
google chrome now, and actually have a
look at the actual RSS feed - the XML data
behind all this - just to see what it
looks like. And as I mentioned, there's a
few ways to do that. If we're using
Google's Chrome browser, you can already
see the XML, and Microsoft's edge browser
will also display the XML. But if
you've got Firefox or you've got a
browser that doesn't directly show the
raw XML, what you can generally do, is
right-click somewhere on the page, like I
can in Firefox - a view page source - and
that will actually give you the same XML
anyway. So at this stage, I'm going to
close down Firefox because I'm not using
that. I just wanted to show you the
formatted output, and we'll go back to
Google Chrome, which has got the raw XML
without us needing to right-click
and view source. But generally speaking,
if your browser doesn't have the option
to view the page source, check its view
menu or use Chrome, as you can see here,
or Firefox where you can actually right
click and view source. You saw me
doing that. One way or the other, you want
to get the XML showing up on the screen
here. Alright, so in the XML, again, if you
look carefully, we can see here that
under the title, we've got iTunes Store:
Top Free Apps. So an RSS feed is
delivered as XML, and that's got standard
tags such as author and title etc, and
there's a separate feed standard called
Atom. But, it's basically very similar and
the term RSS feed also includes atom
feeds. And in fact, looking at this
particular feed here, this actually uses
the Atom namespace, and that's this bit
of code up here you can see; www.w3.org
slash 2005/Atom. So it's using the
Atom tag names rather than RSS,
but there's very little difference as
far as we're concerned, though. Now even if
you're not familiar with XML, it's still
not too hard to work out what the
information represents. There's an
updated tag, for example, here.
That contains the date and time of the
last update to this feed. And
there's also a closing updated tag -
that's his part here. So the information
about when the feed was updated
is everything between the opening and
closing tags - this is the closing tag I've
highlighted - and the opening tag for
updated that I've highlighted there to
the left.
And scrolling down, we can also see there's
other links there; ID, title, summary, and a
bit further down there's things like
pricing and so forth, as we look down the
page. Now you don't have to understand
too much about this. This is just a way
to share data, with the tags describing
what the data actually means, so that
computers can manipulate that data, and
in this case, display it on the screen. Now,
or in the case of when I was on Firefox,
at least to be able to display it on the
screen. Obviously, in this
particular view with Google Chrome, we're
just looking at the raw unformatted
XML. Now, for our application, we're only
interested in some of this data. So the
application that we're going to write in
this section of the course, is going to
extract the data from some of these
fields or tags, and display it in the app.
Now we're going to be using the entry
tags, and you can see there's an entry
tag here. And the entry tag, you can see,
as you look further along or further
down, contains things like a name for
each app and a summary. We're also going
to display the artist and release date,
and we'll actually load the image URL as
well. Now in this app we won't be
displaying the image, but you'll be able
to see how to do that in the next app.
Now notice how each entry repeats, so
we've got this section here, entry. But
if I scroll down, there's another entry
down here, and scrolling down there's the
third entry. So basically, there's one of
those for each of the top ten apps. And
you can see it better if I go
back up to the top again - if I actually
start collapsing some of these entries
by clicking on the arrow. Click that a
few times,
and you can see that there's 10 entries
there now - one for each of the apps in
the top 10 free apps in the
Apple App Store, as of the time that I'm
recording this video. Now, not all
browsers will let you do that, which is
why I'm using Google Chrome here to
demonstrate this. And, obviously, we can
open it up at any time again, if you want
to see the details or just that one
entry. So basically, though, the data that
we're interested in will be everything
that's in between these two entry tags.
So once we find a starting entry tag, we
can keep loading the information we want
until we find the closing entry tag that
matches the start tag. So basically, we
get everything from, in this case, this
first entry right through down to the
last closing one, which is the slash
forward slash entry - that's what we're
going to be dealing with in this
application we're creating in this section
of the course. Alright, so with that said,
let's switch over to Android Studio now
and get started with our app. Now we're
going to create a new project, obviously,
so I'll just go ahead and do that, and I'm
going to call this one Top 10 Downloader.
I'm going to leave the company domain as
it has been set to previously; learn
programming.academy, just as we did for
the previous apps. Once again, remember if
include Kotlin support isn't checked, you
want to check that if you want
Android Studio to generate Kotlin code,
and you want to make sure it's unticked
if you want Java code. So I'm gonna click
on Next there, and on this next screen
I'm gonna leave the minimum SDK set to
17. Again, we've done that in previous
apps, and leave everything else
unticked. Click on Next, and we're going to
use the Empty Activity template, as
we've done before. Click on Next, and then
finally we going to accept the suggested
names for the activity and layout. And
again, you want to make sure that both
checkboxes here are checked, so that
Android Studio generates a layout for us,
and also so the app's compatible with
previous versions of Android. So I'm
going to click on Finish now, and that's
our project created, or what's actually
in the process as being created. So I'm
going to stop the video here, and in the
next video, we're going to start creating
the code to download the feed data and
extract the information from it. So I'll
see you in the next video.