doInbackground
is invoked on the background thread. No need to create a thread there
txtName = (EditText) findViewById(R.id.inputName);
txtEmail = (EditText) findViewById(R.id.inputEmail);
txtName.setText(subject.getString(TAG_NAME)); // updating ui not possible in doInbackground
txtEmail.setText(subject.getString(TAG_EMAIL));
Secondly you cannot update ui from a background thread. You need to update ui in onPostExecute
.You can return result in doInbackground
which is param to onPostExecute
and update ui there.
You need to look at the docs of AsyncTask
to understand more
http://developer.android.com/reference/android/os/AsyncTask.html
Edit:
Change this
class GetSubjectDetails extends AsyncTask<String, String, String> {
to
class GetSubjectDetails extends AsyncTask<String, String, JSONOBject> {
Then
protected JSONObject doInBackground(String... params) {
JSONObject json =null;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("matrix_id", matrix_id));
json = jsonParser.makeHttpRequest(
url_subject_details, "GET", params);
}catch(Exception e)
{
e.printStacktrace();
}
return json;
}
Then
@Override
protected void onPostExecute(JSONObject json) {
super.onPostExecute(json);
pDialog.dismiss();
// parse json
// update ui
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…