I have two blocks of "validation" code that I need to execute in a specific order, but the code in the onPostCreate() event is firing before the code in the onCreate() event, and I suspect it may have something to do with the Preference Store.
Some pseudo-code may help explain:
onCreate()
{
prefs = PreferenceManager.getDefaultSharedPreferences(this);
email = prefs.getString("email", "noemail@noemail.com").toString();
if (email.equals("noemail@noemail.com"))
{
//user has not supplied email address, show alert dialog
warning();
}
}
The warning() method just builds an alert dialog box letting the user know that they need to enter an email address, and when they click "OK" it launches the Preferences activity so they can supply the email address.
onPostCreate()
{
carrier = manager.getNetworkOperatorName();
if(carrier.equals("SPRINT"))
{
//call web service to validate carrier compatibility
//if web service returns "FALSE" call warning2();
}
}
The warning2() method does the same thing as warning() - it builds an alert dialog to let the user know their carrier is not compatible.
Even though warning() is called in onCreate(), and warning2() is called in onPostCreate(), currently the app is throwing the warning2() dialog box before the warning() dialog box, and I don't understand why.
Is it because the second validation calls a web service and the first validation is checking the Preference store, and somehow the web service call is completing before the Preference store can be accessed?
How can I enforce that the first validation and warning() are dealt with before the second validation and warning2()?