You must use the Asyc Task http://developer.android.com/reference/android/os/AsyncTask.html in the OnCreate function for this operation. And remember that you need to create an interface (here I used EVRequestCallback), with which you need to update the user interface of Activity after the rss download is complete. The following is an example Async task code for an RSS feed.
public class RetrieveRssAsync { public RetrieveRssAsync(Context ct,EVRequestCallback gt) { } public static abstract class EVRequestCallback { public abstract void requestDidFail(ArrayList<EventItem> ei); public abstract void requestDidLoad(ArrayList<EventItem> ei); } public static class RetrieveEventFeeds extends AsyncTask<Void, Void, ArrayList<EventItem>> { Context mContext; private EVRequestCallback mCallback; public RetrieveEventFeeds(Context ct,EVRequestCallback gt) { mContext= ct; mCallback=gt; } private ProgressDialog progress = null; @Override protected ArrayList<EventItem> doInBackground(Void... params) { return retrieveRSSFeed("--URL of RSS here--",this.mContext); } @Override protected void onCancelled() { super.onCancelled(); } @Override protected void onPreExecute() { progress = ProgressDialog.show( mContext, null, "Loading ...",true,true); super.onPreExecute(); } @Override protected void onPostExecute(ArrayList<EventItem> result) {
source share