Show progress text while logging user in - Android App

I'm working on an Android app and am having trouble updating the GUI. Basically what I want to achieve is when my user clicks the Sign In button, call the setVisibility method on the groupLogInProgress as defined below and set it to View.VISIBILE. Then fire off my method that logs them in, and if it returns a success value, set the groupLogInProgress to View.GONE, and the groupLogInSuccess to View.VISIBLE (displays "Sign In Successful!") pause for a few seconds and start my main intent. If my log in method returns a false, have it set the groupLogInProgress to View.GONE and the groupLogInError to View.VISIBLE. I can't seem to figure out how to make these things happen without causing my app to hang while it waits for the log in method to complete.

Below is what I have so far, any help is GREATLY appreciated!!

//Hide all 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 is simple method that sets all above groups to View.GONE

//Sign in button onClick handler
public void onClick(View v) { 
    loginData = LogInUser(username, password);
if(loginData == null)
{
    //set groupLogInError to View.VISIBLE, all others to GONE
}
else
{       
        //set groupLogInSuccess to View.VISIBLE, all others to GONE and pause for a few seconds to allow user to see "Sign In Successful!" message
    }
}    

Answers


Define an 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 is simple method that sets all above groups to 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 to View.VISIBLE, all others to GONE
  }
  else
  {       
    //set groupLogInSuccess to View.VISIBLE, all others to GONE and pause for a few seconds to allow user to see "Sign In Successful!" message
  }

 }
}

Execute the task:

new LoginTask().execute();

I've glossed over some of the details, but this class will need access to loginData, your View variables, etc, so could be a private class within your Activity. Some of the details left for you, like passing around results, etc


Need Your Help

Precise tracing of IIS and/or SQL

sql-server iis asp-classic

I am experiencing a performance bottle-neck in this website: http://oceanosdecolor.es/ and I'm not able to find it. If you try, you'll see any page (for example, homepage) takes a long time to load...

Create spreadsheet alongside file upload with Google App Script

google-app-engine google-apps-script google-spreadsheet google-spreadsheet-api

I'm having a surprisingly hard time finding basic examples of setting something like this up. I'm pouring through the documentation, but the basic functions simply will not work. Could really use s...