Android 앱에서 진행률 표시 줄을 닫지 않습니다. 객체 막대 객체를 선언하고 doInProgress 함수를 호출하는 String을 가져 와서 v1이라는 객체를 전달합니다. 비동기 작업이 자신의 작업을 완료하면 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 (문자열 resp) –