Skip to content

Instantly share code, notes, and snippets.

@david-batranu
Created November 11, 2013 09:57
Show Gist options
  • Save david-batranu/7410768 to your computer and use it in GitHub Desktop.
Save david-batranu/7410768 to your computer and use it in GitHub Desktop.
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String result = new String();
try {
URL location = new URL(url);
URLConnection connection = location.openConnection();
BufferedReader data = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = data.readLine()) != null) {
result = line;
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result) {
JSONObject json = new JSONObject();
if(result != null){
try {
json = new JSONObject(result);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
updateList(json);
((ArticleListingAdapter) getListAdapter()).notifyDataSetChanged();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment