Fetching news in android
I want to fetch news from web in android. I searched for some sample example in google but I am not able to find any source code.
开发者_开发百科Can any one explain the logic beyond the fetching news in android?
It depends on what you want to query for. Is it a RSS response or is it a JSON response.
In theory you have to do the following. You have to send of a request to your request URL and parse the response be it XML (RSS is XML) or JSON. All that request and parsing stuff is to be done in a background thread so you don't block the main application thread (UI thread or service main thread).
Once you have parsed the data (preferably to objects) you will have to display it as you wish. Depending on your application you might have to persist the data in a SQLite database.
That was a very rough description of what you need to do in principle.
IBM host a plethora of good tutorials.
This tutorial explains everything quite well and provides source: http://www.ibm.com/developerworks/xml/tutorials/x-androidrss/index.html
You need to setup an Http connection, using HttpClient, retrive the HTML, and parse it.
精彩评论