-1
我用asynctask
顯示從JSON但的AsyncTask顯示加載永遠不會死,沒有錯誤,但加載和裝載該代碼doInBackground
功能的AsyncTask永遠不死
@Override
protected void onPreExecute() {
progressDialog.show();
}
@Override
protected Integer doInBackground(String... arg0) {
// check for login response
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
//DatabaseHandler db = new DatabaseHandler(
// activity.getApplicationContext());
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(URL+id_user);
try {
if (json.getString(KEY_SUCCESS) != null) {
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
// Getting Array of Following
user = json.getJSONArray(KEY_USER);
// looping through All Following
for (int i = 0; i < user.length(); i++) {
JSONObject c = user.getJSONObject(i);
// Storing each json item in variable
nama = c.getString(KEY_NAMA);
instansi = c.getString(KEY_INSTANSI);
status = c.getString(KEY_STATUS);
responseCode = 1;
}
} else{
responseCode = 0;
}
}
} catch (NullPointerException e) {
e.printStackTrace();
}
catch (JSONException e) {
e.printStackTrace();
}
return responseCode;
}
@Override
protected void onPostExecute(Integer responseCode) {
if (responseCode == 1) {
headerNama = (TextView)activity.findViewById(R.id.headerNama);
headerInstansi = (TextView)activity.findViewById(R.id.headerInstansi);
buttonStatus = (Button)activity.findViewById(R.id.buttonStatus);
headerNama.setText(nama);
headerInstansi.setText(instansi);
buttonStatus.setText(status);
}else {
progressDialog.dismiss();
activity.showDashboardError(responseCode);
}
}
我覺得在doinbackground沒有probleme數據,請大家幫幫忙謝謝
你能發佈完整的異步任務? – zennon
可能重複的[AsyncTask線程永遠不會死(Android)](http://stackoverflow.com/questions/3077461/asynctask-threads-never-die-android) – Raghunandan
我已編輯與完整的asynctask請幫助 –