RSS

Category Archives: Android OS

9 How To: RSS and News Feeds

RSS is a term that encompasses a number of web feed formats used in the publication of frequently updated works such as information on news-related sites, blogs, forum posts. Articles can contain both text and links to media such as images, movies etc.

What does RSS actually stand for? – there are several expansions of the term RSS such as Really Simple Syndication, Rich Site Summary etc. Here some descriptions of RSS:-

RSS Explained:-
http://www.whatisrss.com/

Wikipedia RSS
http://en.wikipedia.org/wiki/RSS

.
The most commonly used formats are RSS followed by Atom. HAC can process both these formats plus some custom formats as well. It can also process sources from either a URL or a text file. Usually the term RSS is generic and refers to RSS plus Atom and custom formats.
.
With HAC, users do not have to specify the format because HAC tries to be flexible and process as much of each article as possible. For each article it is asked to keep, it saves every field it can parse, and also saves their field names. This allows the programmer/user to decide which fields to use. Fields are created by HAC in the order in which they were found.

Apps handling news feeds need some protection because RSS feeds can potentially be huge and any attempt to download/process the entire feed could cause a memory exception in the app. Therefore HAC allows feeds to be interrogated for their size and has options to process a specified range of articles. For instance, if there were 1000 articles in the source, then the user might like to just look at articles in the range 100 to 150 without downloading/parsing the entire source.
.
.
Example Feeds
Here are some example feeds used in testing the HAC RSS example project.

Atom feed
http://blog.case.edu/news/feed.atom

HAC Forums RSS:-
http://www.tigabyte.com/forum/index.php?action=.xml;type=rss

BBC News Feed:-
http://feeds.bbci.co.uk/news/world/middle_east/rss.xml

Global Sport feed:-
http://globoesporte.globo.com/dynamo/futebol/times/vasco/rss2.xml
.
.
Reading Feeds
There are 3 steps in using RSS

  1. Get feed from URL or a file.
  2. Parse the feed for articles.
  3. Examine or display articles.

The format of articles is explained below.

.

Feeds and Articles

Feeds are comprised from a number of articles and each article can have several named fields although there can be more than one field with the same name. The situation can be more complex though as some sources use custom formats where fields have sub fields etc. Custom formats are more complex to parse and HAC RSS parsing currently doesn’t support them as its parser just looks for top level elements/fields.

The list below shows comparative field names for RSS and Atom although there is nothing to stop sources having their own unique field names:

.
.

EXAMPLE: Creating an RSS Reader

Here we will show you the scripts behind a basic RSS reader that can work with the formats: RSS, Atom and some custom ones. As mentioned above there are 3 stages to reading an RSS feed although HAC combines both the fetch and parse stages into one function. Note, for clarity, it does not show any error checking.

a) Open and Parse Feed

To parse an RSS source use the RssParseSourceFN function. This function returns a count of the number of articles found although if an error occurred it returns -1. It automatically stores any retrieved articles and their field names so later they can be processed or displayed. Note, for app safety, a maximum article limit must be specified so for instance if the feed contained a million articles then your app could limit itself to just 100 articles. There is also a start value that enables a number of articles to be skipped.

The code below shows how to parse an RSS feed:-

@ --- Reads BBC news source ---
Local mode,source,start,max

@ read from URL so set mode = 2 (=1 for file)
PUT 2 INTO mode

@ Set URL
PUT 'http://feeds.bbci.co.uk/news/world/middle_east/rss.xml' INTO source

@ Set limits
PUT 1 INTO start
PUT 100 INTO max

@ Retrieve and parse source
PUT RssParseSourceFN(mode,source,start,max) INTO field 1

@ Display article count found
PUT RssArticleCountFN INTO field 2

.
It you just want to count how many articles are in the source then use the RssParseCountFN function. This parses the source but does not store any articles. Again, for safety it requires the maximum number of articles to parse. The example below shows how to do this.

@ --- Reads BBC news source ---
Local mode,source,max

@ read from URL so set mode = 2 (=1 for file)
PUT 2 INTO mode

@ Set URL
PUT 'http://feeds.bbci.co.uk/news/world/middle_east/rss.xml' INTO source

@ Set limits
PUT 10000 INTO max

@ Parse and count source
PUT RssParseCountFN(mode,source,max) INTO field 1

.

b) Accessing Retrieved Articles

Once the articles are retrieved to memory then they can be processed and displayed. The RssArticleCountFN returns the number of articles previously retrieved and can be used to loop over the articles.

Each article has a number of named fields such as AUTHOR, CATEGORY, DESCRIPTION etc. There is no restriction though on uniqueness of the field names so for example an article might have several fields named DESCRIPTION. Furthermore, articles within the same feed can have different numbers of fields and different field names. The number of field names and a list of their names can be retrieved using the functions RssFieldCountFN and RssFieldNamesFN respectively. Note, all field names are forced to uppercase. There is also a function called RssFieldListFN that returns in list form the name of every field found in the source.
.
The script below shows how to retrieve the contents of a known named field called DESCRIPTION from article number 5.

@ --- Display DESCRIPTION field of article 5 ---

PUT RssFieldByNameFN(5,'DESCRIPTION') INTO field 1

.
.

The script below shows how to loop over all of the fields in article 5.

@ --- Displays article 5 ---
Local aid,count,f

@ set article number
PUT 5 INTO aid

@ how many fields
PUT RssFieldCountFN(aid) INTO count

@ Loop over all fields and place into text field 1
Clear field 1
FOR f=1 TO count
   PUT RssFieldByNumberFN(aid,f) AFTER field 1
ENDFOR

.
.
c) Tidying Up

Once you have finished using the retrieved articles it is a good idea to clean up and free the memory they occupied, especially if hundreds or more articles were retrieved. The RssClear command frees memory used for storing all article headers, fields and articles themselves.

@ --- Clear memory used by RSS ---

RssClear

.
.

.
Summary
This article shows how to create a very simple RSS reader using HAC and briefly looks at a few of its RSS commands/functions. For more details see the project link below.

With HAC an RSS app can:

  1. Read RSS, Atom and some custom formats.
  2. Read from either a URL feed or a text file.
  3. Limit the number of articles parsed
  4. Skip articles and retrieve just a range.

For more information about creating RSS apps with HAC, look at HAC’s built-in help or its HAC Help pdf.

There is an RSS project and its built app on our examples web page http://www.hypernextandroid.com/hnfiles/rescreator.html The project example is only test bed that demonstrates HAC’s RSS functionality.

.

Members of HAC forums can download the latest trial version of HAC, see details here:- http://www.hypernextandroid.com/hnfiles/downloads.html

 

HAC and Developing on the Kindle Fire

Yesterday we took our initial look at Amazon’s Kindle Fire tablet and were surprised at its quality of build, display and touch response especially as compared to our budget Android tablets. The Kindle Fire runs a modified version of Android Gingerbread and therefore has some differences from the official Google Android Gingerbread. For instance it doesn’t have the buttons Home, Back and Menu that most Android devices have but instead uses a special menu bar at the bottom of its screen.

Running HAC built Apps
Once we had the Kindle booted up and wifi working we used the Kindle Fire’s web browser to load some of the example apps built by HAC from our website’s projects web page. Kindle Fire’s built in web browser is easy to use and we tried several of the demos including Solar System and they all worked. The Android Info demo accurately identified the device hardware as Kindle Fire so anyone building apps with HAC can be sure their app can successfully detect if it is indeed running on a Kindle Fire.

Some Android developers using the official Android SDK have reported a menu bar problem with the Kindle Fire and we were keen to check this out. At the present time the Kindle Fire’s bottom menu bar cannot be programmatically removed by apps built with the official Android SDK and so the bottom 40 pixels of such apps are always hidden. Amazon do make their Kindle SDK available to developers aiming to create apps specifically for the Kindle Fire and their SDK has the necessary functionality to hide, show and detect the bottom menu bar so allowing apps to use the full screen. However, as HAC won’t be using the Kindle SDK we have a fix in mind to limit the affects of the menu bar problem.

We wanted to connect HAC to the Kindle Fire so as to build and debug apps but amazingly the KIndle Fire doesn’t come with the necessary USB micro B connection cable so we had to order one.

Using HAC to launch and debug apps on Kindle Fire
Today our USB connection cable came but before we could connect up the Kindle Fire to our Windows XP development machine we had to modify a couple of files associated with the Android ADB and USB driver. Soon we will have more details on this but for now here is a link on how to do this :-

http://mobile.tutsplus.com/tutorials/android/getting-started-with-kindle-fire-development/

By the way, there is a free editor called Notepad++ that is great for editing such files:-

http://notepad-plus-plus.org/

Once we had the USB drivers set up we plugged in the Kindle Fire and started up HAC. From HAC’s “Manage Devices” menu we could see the attached Kindle Fire and therefore ran the DDMS debugger before testing a few projects. Please note that the current version of HAC (v1.12) was used and had not been modified in any way in order to work with the Kindle Fire so we weren’t sure what to expect.

We tried several demo projects such as Hello World, Android Info, Preschool Sums and Lunar Lander. They all worked but we noticed a few problems such as the Kindle menu bar remaining at the bottom of the screen, sometimes images not updating after pressing the Home button and then returning to the app. At least there we no crashes, the button response and graphics events worked as well. The Lundar Lander game ran smoothly and below is a screenshot that shows the Kindle menu bar at the bottom of the screen.

Lunar Lander on Kindle Fire

Summary
The Kindle Fire is a very good tablet even though it is running a modified Android OS. Apps built by the current version of HAC do run on it although the bottom menu bar is an irritation as it take valuable space that an app could use.
Our next move is to modify the forthcoming v1.13 release of HAC to work even better with the Kindle Fire.

 
 

Tags: ,

Android more reliable than Apple iOS

This short post is about a very interesting article from PCWorld entitled:¬†“Who’s the Smartphone OS Crash Champion?” that presents app crash stats and concludes that Android apps crash far less frequently than iOS apps. For details on the crash reports see the article and its graphs.
http://www.pcworld.com/article/249356/whos_the_smartphone_os_crash_champion.html#tk.hp_fv

Essentially the article examines, quotes and shows the crash results from apps as reported by the mobile app monitoring company Crittercism at
http://www.crittercism.com/index.html

There is also more data and an analysis from Forbes at
http://www.forbes.com/sites/tomiogeron/2012/02/02/does-ios-crash-more-than-android-a-data-dive/

Android and iOS
If one takes a very brief look at the articles it might appear that it is the mobile operating systems crashing whereas the reports are actually about apps crashing. Does it matter? Yes, most certainly, because if the operating system crashes it probably needs a reboot of the phone or tablet device and that could lose the users current work or data. Of course a really badly behaved app can deprive the the operating system of resources and perhaps even make it crash, so crashing apps are still a bad thing.

Why the Differences?
Assuming that on average the percentage  of Android apps crashing is far less than the percentage of iOS apps crashing then why should this be? The authors and commenters give a number of reasons but only detailed analysis would really shed light on what is actually happening. Anyhow, here are a few suggestions they made:-

(1) Is it the operating system? Well Android is better at multi-tasking so perhaps it is better at house-keeping, memory, stability etc. The problem is how to measure this from the reports.

(2) Is it the number of operating systems? They suggest that perhaps because there are so many different versions of each operation system therefore developers are having problems making their apps work on each version. However, their stats were from 33 versions of Android and 23 versions of iOS so one might expect the Android to be worse when the contrary is true.

(3) Is it the memory management? – I’m not an iOS programmer so can’t vouch for it but some iOS programmers say it is much more difficult managing the memory on iOS than on Android as the programmer themselves must do it. If true, this would make it much more likely that newbie programmers on iOS would produce less reliable apps than those on Android.

(4) Is it the development languages? – some say Java is more robust than Objective C although Java certainly gives the inexperienced programmer lots of scope to crash their app.

(5) There is also talk of the inbuilt advertising making apps unstable. That might be true because if something in the app starts connecting to the net it might interfere with the app’s natural stability.

(6) There is also the hardware but Apple tightly controls its hardware whereas Android runs on a wide variety of devices from different manufactures. Again, Android should fare worse than iOS but the opposite is true.

Conclusions
Clearly by the reported stats Android apps crash far less than iOS apps but there doesn’t seem a clear case for why it should be. There are so many variables here, different versions of operating system and hardware, types of app, what the app does, and how it interacts with hardware. Perhaps the Android OS is more stable than iOS, time will tell. However, they are both developing so rapidly, so watch this space.

 
Leave a comment

Posted by on 07/02/2012 in Android OS, iOS