Values back from Async tasks in a useful way

Values back from Async tasks in a useful way

When a student logs in to the current version of the Android app an Async task makes a web service call which returns a private key if the credentials match.

This key is used for subsequent calls from the app as this is a much safer solution than asking students to log in to remote systems every time the app opens.

An Async task is necessary because network activity has to happen off the main thread.

This is how the login process works from clicking the Students button on the home page.

A handler activity class with a simple layout file is loaded which carries out the following tasks.

  1. checks for Internet connectivity and shows a try again button in the layout if no connectivity is found.
  2. checks the contents of the local storage to see if the student already has a private key
  3. if no private key is found our work is done in this activity and then the Login activity is opened.
  4. If the private key is found the contents of the file are checked (via another web service call) and if found to be valid the Student information activity is launched without showing any layout.

I’m interested in point 3 here. The login activity is being launched because the student has not logged in before or their private key has expired.

Now the student will be looking at the login form. Upon entering a username and password then clicking the login button the following happens:

newlogin

  1. The username and password are read into variables
  2. A new remote login check is carried out (Async task)
    1) The credentials are passed (via SSL) to web service I capture the returning XML using a DocumentBuilderFactory object.
    2) The XML is parsed into an Array which is passed to the onPostExecute function.
    3) The onPostExecute saves the user information into the local storage. If this is successful the Student Information activity is launched.

The result of a successful login. This activity is only shown if the key file is written (subsequently read) successfully.

studentinformation
(early prototype student activity)

Next time using web views to show the student useful things.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.