I\'m trying to get data from a website and parse it into my android application. Unfortunately I don\'t even get to the part of parsing the data. The code doesn\'t run after the
Alike Dale Wilson said, you can't update UI in doInBackground method. Prefer onPreExecute and onPostExecute methods.
You can also update your message TextView with the result of your doInBackground like that :
private class getinternetData extends AsyncTask{
@Override
protected String doInBackground(String... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://www.google.com");
try{
//message.setText("333");
HttpResponse response = httpclient.execute(httpget);
//message.setText("444");
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if(statusCode == 200){
return "Could connect";
}else
return "Couldn't connect";
}catch(Exception e){
return e.toString();
}
return null;
}
@Override
protected void onPostExecute(String result) {
if (result != null)
message.setText(result);
}
}