multithreading - Show progress text while logging user in - Android App -


i'm working on android app , having trouble updating gui. want achieve when user clicks sign in button, call setvisibility method on grouploginprogress defined below , set view.visibile. fire off method logs them in, , if returns success value, set grouploginprogress view.gone, , grouploginsuccess view.visible (displays "sign in successful!") pause few seconds , start main intent. if log in method returns false, have set grouploginprogress view.gone , grouploginerror view.visible. can't seem figure out how make these things happen without causing app hang while waits log in method complete.

below have far, appreciated!!

//hide sign in progress/success/error layouts oncreate grouploginprogress = (linearlayout) findviewbyid(r.id.grouploginprogress); grouploginsuccess = (linearlayout) findviewbyid(r.id.grouploginsuccess); grouploginerror = (linearlayout) findviewbyid(r.id.grouploginerror);         hideallstatus(); //this simple method sets above groups view.gone  //sign in button onclick handler public void onclick(view v) {      logindata = loginuser(username, password); if(logindata == null) {     //set grouploginerror view.visible, others gone } else {                //set grouploginsuccess view.visible, others gone , pause few seconds allow user see "sign in successful!" message     } }     

define asynctask:

private class logintask extends asynctask<void, integer, integer> {  static final int status_success = 1;  static final int status_fail = 0;   @override  protected void onpreexecute()  {   hideallstatus(); //this simple method sets above groups view.gone  }   @override  protected integer doinbackground(void... params)   {   logindata = loginuser(username, password);   return (logindata == null ? status_fail : status_success);  }   @override  protected void onpostexecute(integer result)  {   if (result == status_fail)   {     //set grouploginerror view.visible, others gone   }   else   {            //set grouploginsuccess view.visible, others gone , pause few seconds allow user see "sign in successful!" message   }   } } 

execute task:

new logintask().execute(); 

i've glossed on of details, class need access logindata, view variables, etc, private class within activity. of details left you, passing around results, etc


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -