You have a runOnUiThread
. Remove it. It should be used only for updating ui not for http get request.
Using AsyncTask
is a better option. Make the http get request in doInBackground
and parse the response also. You can return the result in doInbackground
which is a param to onPostExecute
.
So you can update ui in onPostExecute
which is invoked on the ui thread.
http://developer.android.com/reference/android/os/AsyncTask.html
Example:
To invoke
new TheTask().execute(); // in ui thread
Make AsyncTask
an inner class of activity
class TheTask extends AsyncTask<Void,Void,String>
{
@Override
protected String doInBackground(Void... params1) {
String response = null;
try {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setSoTimeout(params, 0);
HttpClient httpClient = new DefaultHttpClient(params);
String urlString = "http://url";
HttpGet httpget = new HttpGet(urlString);
HttpEntity entity = httpClient.execute(httpget).getEntity();
response = EntityUtils.toString(entity);
httpClient.getConnectionManager().shutdown();
}
catch(Exception e)
{
e.printStackTrace();
}
return response;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
JSONArray jsonarray = new JSONArray(result;
JSONObject jb =(JSONObject) jsonarray.getJSONObject(0);
String name= jb.getString("name");
String punkt = jb.getString("punktezahl");
fuehrender.setText(name);
punkte.setText(punkt);
}
}