我不完成關閉我的Android應用程序進度條。 我聲明一個對象欄對象並獲取一個調用doInProgress函數的字符串並將它傳遞給一個名爲v1的對象。 當異步任務完成他的任務時,爲什麼進度條(出現wichs)不會像onPostExecute方法中聲明的那樣被解僱?進度條不排除
在我的活動我打電話:
ProgressDialog pDialog;
response = new GetString(SecondActivity.this).execute(v1).get();
,這是myAsync任務:
package com.gms;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
public class GetString extends AsyncTask<VariablesTable, Void, String> {
private Context context;
public ProgressDialog pDialog;
public GetString(Context c){
context = c;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(context);
pDialog.setMessage("Loading..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected void onPostExecute() {
// dismiss the dialog once got all details
if (pDialog.isShowing()){
pDialog.dismiss();
}
}
@Override
protected String doInBackground(VariablesTable... obj) {
// Making HTTP request
InputStream is = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(obj[0].cat, "utf-8");
obj[0].url += "?" + paramString;
HttpGet httpGet = new HttpGet(obj[0].url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}
}
建議? 在此先感謝
我認爲你的異步任務不行。而onPostExecute不是calle –
問題是:你知道爲什麼onPostExecute沒有被調用? – FrankBr
嘗試更改onPostExecute()onPostExecute(String resp) –