Android - onPostCreate() code firing before onCreate() code

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()?

Answers


Are you sure it's calling the warning2 dialog first, or are you just seeing it first? Dialogs don't block the main activity, so it's probably calling warning first, but immediately after that, it calls warning2, which would cover the first dialog. So you would see warning2, and not see warning until it was dismissed, since it's layered directly below it.


Need Your Help

How to get Windows Phone 7 emulator to use hardware acceleration?

graphics windows-phone-7 emulator nvidia

I'm running the Windows Phone 7 dev tools on an older MacBook Pro, with an NVIDIA GeForce 9400M graphics card with 256MB of memory (not sure if it is shared or not) and I get lots of stuttering in ...

Does CGImageGetDataProvider depend on type of image?

iphone objective-c osx ipad

I used CGImageGetDataProvider and CGDataProviderCopyData and then get a pointer to the data. The first image I tested was a bmp and this method worked great. However, I changed my image to a JPG

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.