Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by Niklas Lindblad for How to store RSS feeds in Android?

First off, do not rely on the titles being unique. Instead, use the guid field which is meant to be the unique identifier for the item (see the RSS specification).

Updating feed

Go through each item in the retrieved feed and see if the guid already exists in the database, if so, skip it.

If it does not exist, create an entry.

So, revising your logic:

  1. Start parsing the RSS feeds.
  2. Read the guid of the newly fetched RSS feed.
  3. Does it match the guid of any row in the database?3.1. No, then keep parsing and add this feed to the database.3.2. Yes, then stop parsing and add this feed to the database.

Order of the items

There is also a field called pubDate which indicates when the item was published. Simply store the pubDate for each item in the database and use it in an ORDER BY clause when retrieveing:

SELECT * FROM items ORDER BY pubDate DESC

That will give you the items in order of original publication.

UPDATE: Since SQLite does not have a native data type for dates, you could either utilize the time/date helper functions or convert pubDate to epoch format in your code before you insert it into the database.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>