android - Do not run ProgressDialog while another AsyncTask -
i show progressdialog during asynctask.
i write progressdialog . 1 asynctask , write asynctask in postexecute method.
but progressdialog doesn't run... i'd appreciate kind help.
asynctask code:
public class savingprogresstask extends asynctask<void, void, void> { private context mcontext; private progressdialog progdialog = null; public savingprogresstask(context context) { mcontext = context; } @override protected void onpreexecute() { super.onpreexecute(); progdialog = new progressdialog(mcontext); progdialog.setmessage("saving..."); progdialog.setindeterminate(false); progdialog.setprogressstyle(progressdialog.style_spinner); progdialog.setcancelable(false); progdialog.show(); } @override protected void doinbackground(void... params) { return null; } @override protected void onpostexecute(void avoid) { super.onpostexecute(avoid); if(isupdatestore) { try { int storeresponsemessage = new storeupdatetask(settingactivity.this).execute(fc_code).get(); if(storeresponsemessage == 1) { store updatestore = new storedetailtask(settingactivity.this, false).execute(fc_code).get(); mauthuser.setstore(updatestore); userauthutil.saveuserobject(settingactivity.this, mauthuser); } } catch (interruptedexception e) { e.printstacktrace(); } catch (executionexception e) { e.printstacktrace(); } } int userinforesponsemessage; int userinfosex; if(msextextview.gettext().tostring().equals("남자")) { userinfosex = 1; } else if (msextextview.gettext().tostring().equals("여자")){ userinfosex = 2; } else { userinfosex = 2; } if(isupdatebirthday) { if(isupdatesex) { try { userinforesponsemessage = new userupdatetask(settingactivity.this, true, "twice").execute(tempbirthday, string.valueof(userinfosex)).get(); if(userinforesponsemessage == 1) { mauthuser.getuser().setbirthday(tempbirthday); mauthuser.getuser().setsex(userinfosex); userauthutil.saveuserobject(settingactivity.this, mauthuser); } } catch (interruptedexception e) { e.printstacktrace(); } catch (executionexception e) { e.printstacktrace(); } } else { try { userinforesponsemessage = new userupdatetask(settingactivity.this, true, "birthday").execute(tempbirthday).get(); if(userinforesponsemessage == 1) { mauthuser.getuser().setbirthday(tempbirthday); userauthutil.saveuserobject(settingactivity.this, mauthuser); } } catch (interruptedexception e) { e.printstacktrace(); } catch (executionexception e) { e.printstacktrace(); } } } else { if(isupdatesex) { try { userinforesponsemessage = new userupdatetask(settingactivity.this, true, "sex").execute(string.valueof(userinfosex)).get(); if(userinforesponsemessage == 1) { mauthuser.getuser().setsex(userinfosex); userauthutil.saveuserobject(settingactivity.this, mauthuser); } } catch (interruptedexception e) { e.printstacktrace(); } catch (executionexception e) { e.printstacktrace(); } } else { } } if(progdialog != null) { progdialog.dismiss(); intent intent = new intent(mcontext, homeactivity.class); intent.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_top); mcontext.startactivity(intent); } } in click listener:
savingprogresstask savetask = new savingprogresstask(settingactivity.this); savetask.execute();
as far know starting async task post execute of previous async task not idea.
when had similar problem in 1 of projects had followed following process.
1) create interface method notifyuithread().
2) implement interface activity, calls async task.
3) while creating async task, pass 'this' parameter constructor of async task.
4) in post execute of async task call this.notifyuithread() method.
5) in overridden method notifyuithread(), make call next async task.
coming progress dialog, make global variable, show in pre execute method of first async task, dismiss in post execute of second async task.
you can make progress dialog local async task, show in pre execute , dismiss in post execute of both async tasks.
but small advice here is, keep app responsive. showing progress dialog long time not advisable.
Comments
Post a Comment