Pay It Square utilizes a token based authentication approach to indicate an authenticated request and map the request to the particular user authenticated. This token is generated during the login process and can be stored on the device itself for future use.
In addition to the login, it is necessary to also load some satellite data for currency information, finally if the request is authenticated we attempt to load the Collect Pages for the user.
While this could all be done in an Async Task associated with the Login Screen, I felt it would be a better experience to use a Splash Screen, in which we would perform these operations and provide a friendly indication of progress to the user. The following code shows the Async process taking place as part of the load. The Splash Screen is really no different then a normal Activity in the app, except that there is less control on the part of the user as to when it finishes, its handle programmatically instead.
The processing should be done off the onCreate method through an async task. You don’t want to do this on the main thread and risk hitting the 5s limit the Android places on applications before considering “Not Responding”.
The important thing here is that when the process is complete that you call finish on the activity as you start the next activity (see below):
The reason you do this is to the user cannot reach the splash screen with the hardware back button. This is a common tactic with Android apps so as to enforce control over the path the user takes, especially with respect to the user using the back button.
One of the things that I will point out that differs here from the previous version of the Pay It Square Android app (unreleased) is that instead of using SQLite, I used the Preferences engine to store the token rather then the database (see below):
This is a simple wrapper class that saves the AuthToken and Username to the Preference file associated with the app. This is a very easy way to save and retrieve simple data rather then incurring the cost of setting up and maintaining a SQLite database on the device.