android - ProgressDialog in AsyncTask called from DialogFragment is not shown -
i executing asynctask inside dialogfragment progress bar not shown during doinbackground. here code:
public class getcustomersoapasync extends asynctask<void, void, string> { progressdialog prg; actionbaractivity activity; getresponsefromgetcustomer listener; public getcustomersoapasync(actionbaractivity activity, getresponsefromgetcustomer listener) { this.activity = activity; this.listener = listener; prg = new progressdialog(activity); prg.setmessage("lütfen bekleyin"); log.i("ed","progress shown"); prg.show(); } @override protected string doinbackground(void... params) { //some stuff } @override protected void onpostexecute(string s) { listener.getresponsefromgetcustomer(s); if (prg.isshowing()) { prg.dismiss(); } } and call it:
public class b1_phonenumberfragment extends android.support.v4.app.fragment { ... buttonlogin.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { ... phonenumberverified dialog = new phonenumberverified(); dialog.show(getfragmentmanager(), "numberverifiedbyuser"); } ... } .... public class phonenumberverified extends dialogfragment { @override public dialog oncreatedialog(bundle savedinstancestate) { // use builder class convenient dialog construction alertdialog.builder builder = new alertdialog.builder(getactivity()); // format of dialog changed builder.setmessage("numaranız doğru mu?\n" + "0" + number) .setpositivebutton(r.string.yes, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { globalapplication.getuser().setphone( (excludeparanthesis (number))); //asynctask not working properly, // progress dialog not shown , code flows before // response set s getcustomersoapasync getcustomersoapasync = new getcustomersoapasync( (actionbaractivity) getactivity(), new getresponsefromgetcustomer() { @override public void getresponsefromgetcustomer (string s) { response = s; } }); getcustomersoapasync.execute(); log.i("ed", "response after getcustomersoapasync callback: " + response); } and finally, maybe because of flawed flow of tasks or maybe else, callback can't job, , response not set return value of asynctask.
thanks help!
you should use onpreexecute :
class task1 extends asynctask<object, void, string []> { /** progress dialog. */ private final progressdialog dialog = new progressdialog(youractivity.this); /** * set progress dialog. */ protected void onpreexecute() { super.onpreexecute(); this.dialog.setmessage("loading..."); this.dialog.show(); dialog.setcanceledontouchoutside(false); } protected string[] doinbackground(object... params) { /// } protected void onpostexecute(string [] result) { super.onpostexecute(result); this.dialog.dismiss(); } } to call should:
task1 mytask = new task1(); mytask.execute(stoparrey, start, end); hope helped! :)
Comments
Post a Comment