I have an RSS reader which display the titles of a RSS feeds in a list. on clicking the title the 开发者_运维百科main source page of the title should open... the following code works fine for a small list but if i have a long list which contains feeds from more than one website the application stops and i have to force close it. can anybody help me to fix it please.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent viewMessage = new Intent(Intent.ACTION_VIEW,
Uri.parse(messages.get(position).getLink().toExternalForm()));
this.startActivity(viewMessage);
}
It's possible, depending on how many pages you're parsing, you'll want to start an asynchronous task. Basically you'll start a new thread separate from your UI thread so you won't have to force close the application. Read more about asynchronous tasks here:
http://developer.android.com/reference/android/os/AsyncTask.html
Also - if you implement error checking you'll be able to continue to run the application if you do get an exception from parsing.
精彩评论