ProgressDialogNotApperBeforalDialogInAndroidApp
在Android应用程序中,进度对话框应该出现在显示警报对话框之前。我正在使用android studio 警报对话框内容将来自单独类文件中的异步任务。因此,从异步任务执行进度对话框 但在AlertDialog打开之前,我无法看到进度对话框屏幕 下面是我的异步任务代码ProgressDialogNotApperBeforalDialogInAndroidApp,android,android-studio,Android,Android Studio,在Android应用程序中,进度对话框应该出现在显示警报对话框之前。我正在使用android studio 警报对话框内容将来自单独类文件中的异步任务。因此,从异步任务执行进度对话框 但在AlertDialog打开之前,我无法看到进度对话框屏幕 下面是我的异步任务代码 public class ResidentsPaymentInfoHttpResponse extends AsyncTask<String, Void, List<paymentInfo>> { P
public class ResidentsPaymentInfoHttpResponse extends AsyncTask<String,
Void, List<paymentInfo>> {
ProgressDialog pDialog;
private Context MSAContext;
public ResidentsPaymentInfoHttpResponse(Context context) {
MSAContext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = ProgressDialog.show(MSAContext,"Autenticando", "Contactando o
servidor, por favor, aguarde alguns instantes.", true, false);
}
@Override
protected List<UserPaymentInfo> doInBackground(String... params){
String flatNo = params[0];
String urls = "https://script.google.com/macros/s/;"
List<UserPaymentInfo> residentsMonthlyPayments = new ArrayList<>();
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(urls)
.build();
Response responses = null;
try
{
responses = client.newCall(request).execute();
String jsonData = responses.body().string();
JSONObject jobject = new JSONObject(jsonData);
JSONArray jarray = jobject.getJSONArray("ResidentsInfo");
int limit = jarray.length();
for(int i=0;i<limit; i++)
{
JSONObject object = jarray.getJSONObject(i);
if(object.getString("FlatNo").equals(flatNo) &&
object.getString("PaymentStatus").equals("notpaid")) {
UserPaymentInfo residentMaintePayment = new
UserPaymentInfo();
UserInfo residentInfo = new UserInfo();
residentInfo.setUserFlatNo(object.getString("FlatNo"));
residentsMonthlyPayments.add(residentMaintePayment);
}
}
}
catch (IOException e)
{
// e.printStackTrace();
}
pDialog.dismiss();
}
catch (Exception ex)
{
// ex.printStackTrace();
}
return residentsMonthlyPayments;
}
protected void onPostExecute(List<UserPaymentInfo> rusult){
super.onPostExecute(rusult);
pDialog.dismiss();
}
}
我遗漏了什么吗?您不应该更新doInBackground中属于主/UI线程的UI元素。可能正在删除pDialog.discover;从doInBackground的结束行更改情况。检查下面的链接。 您没有在“进度”对话框中调用“显示方法”。您应该在preExecute中执行它,然后在异步任务的postExecute方法中取消它
同样正如VSB所说,您不应该从doInBackground方法更新UI元素。没有Alertdialog的可能重复!