这是奇怪的事情,有时当我来到我的活动时,它会调用asyncTask,这是我使用ProgressDialog的代码
ProgressDialog ringProgressDialog ;
@Override
protected void onPreExecute()
{
super.onPreExecute();
ringProgressDialog= ProgressDialog.show(Myactivity.this, null,"message", true);
}
@Override
protected void onPostExecute(String result)
{
super.onPostExecute(result);
ringProgressDialog.dismiss();
}
有一天asynctask得到错误,我想发布错误,但不知怎的,我没有错误。
这是什么问题?为什么它有时会出错,有时它运行正常? 我确定问题来自progressDialog。
谢谢
答案 0 :(得分:0)
ProgressDialog ringProgressDialog ;
@Override
protected void onPreExecute() {
super.onPreExecute();
ringProgressDialog= ProgressDialog.show(getApplicationContext(), null,"message", true);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if(ringProgressDialog.isShowing())
ringProgressDialog.dismiss();
}
答案 1 :(得分:0)
以其他方式尝试
ProgressDialog pDialog;
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(Activity.this);
pDialog.setMessage("Fetching News...");
pDialog.setCancelable(false);
pDialog.show();
}
答案 2 :(得分:0)
请尝试这种方式,希望这有助于您解决问题。
public void getDataFromServer(final Context context){
new AsyncTask<Void,Void,Void>(){
ProgressDialog ringProgressDialog ;
@Override
protected void onPreExecute() {
super.onPreExecute();
ringProgressDialog= ProgressDialog.show(context, null,"message", true);
}
@Override
protected Void doInBackground(Void... params) {
// write your service call code here
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
ringProgressDialog.dismiss();
}
}.execute();
}
答案 3 :(得分:0)
ProgressDialog pDialog;
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog("Your Activity");
pDialog.setMessage("Your message");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
pDialog.dismiss();
}