java - Android dialog box and Async Tasks -


i trying make progress dialog pop while things loading. have figured out how make dialog boxes appear , disappear , can change whats in them have multiple async tasks , want dialog appear when first async task starts , disappear when last async tasks finishes.

is there way dialogs know when async tasks complete given activity? having problems on how approach issue. help!

here exact sample code used acheive same functionality.

public class loginactivity extends activity  {     public static string tag = "login_activity: ";      private edittext usernameedittext;     private edittext passwordedittext;      private progressdialog progress_dialog;      private int taskcount = 0;      private void updatetaskcount(int value)     {         taskcount += value;          if(progress_dialog != null && taskcount == 0)         {             progress_dialog.dismiss();         }     }      @override     protected void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_login);          usernameedittext = (edittext) findviewbyid(r.id.login_username);         passwordedittext = (edittext) findviewbyid(r.id.login_password);          progress_dialog = new progressdialog(this);     }      public void loginclick(view view)     {                string url = "http://some.com/api/members?username=" +                                               usernameedittext.gettext().tostring()+ "&password=" +                         passwordedittext.gettext().tostring();           progress_dialog.setmessage("authenticating. please wait...");          progress_dialog.setcancelable(false);          progress_dialog.show();           new authenticateuserfromserver().execute(url);          updatetaskcount(1);           new notifywebservice ().execute("some other url");          updatetaskcount(1);         }      protected void ondestroy()     {         progress_dialog.dismiss();         super.ondestroy();     }      @override     protected void onpause()     {         progress_dialog.dismiss();         super.onpause();     }      private class authenticateuserfromserver extends asynctask <string, void, string>      {         protected string doinbackground(string... urls)         {             return utility.readjsonfromwebservice(urls[0]);         }          protected void onpostexecute(string result)          {                // other stuff              updatetaskcount(-1);         }     }      private class notifywebservice extends asynctask <string, void, string>      {         protected string doinbackground(string... urls)         {             return utility.readjsonfromwebservice(urls[0]);         }          protected void onpostexecute(string result)          {                // other stuff              updatetaskcount(-1);         }     } } 

if have multiple/separate classes async tasks can create static utility class keep track of , update count.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -