1

I have the main activity which launches a "loading screen" activity. When the "loading screen" finishes, I need to show a kind of a splash-screen, and naturally I chose Dialog class to do so. But when I call for showDialog from onResume the application fails even though I understand from all the related posts that this is the proper way to do it.

Can anyone point me to the right direction?

Here's a code sample, if it helps:

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_SPLASH:
            promo = new PromoSplashScreen(getAppContext(), R.style.NoFrameNoBorderBoTitle);
            promo.setCancelable(false);
            promo.setImage(ApplicationData.config.splashImageURL);
            return promo;
        default:
            return super.onCreateDialog(id);
        }
    }
    @Override
    protected void onResume() {
        super.onResume();
        if (ApplicationData.config == null) return;
        if (ApplicationData.config.splashEnabled && !ApplicationData.config.splashPlayed && ApplicationData.config.splashImageURL != "") {
            // Play splash screen
            ApplicationData.config.splashPlayed = true;
            showDialog(DIALOG_SPLASH);
        }
    }
Igor K.
  • 583
  • 5
  • 22

1 Answers1

2

Seems that "getAppContext()" is a null value when you invoke it during the dialog creation. This is documented in this thread: Android: ProgressDialog.show() crashes with getApplicationContext

To work around this, they have used a hack wherein they use a thread to show the dialog after some milliseconds of the resumption of the activity. That way, getAppContext is not null when it is invoked.

Community
  • 1
  • 1
Soham
  • 4,842
  • 3
  • 29
  • 47
  • Ahhhh got it, using your log I found out that "getAppContext()" might be null when you invoke the show dialog , this is discussed in this thread and there is also a hack to work around that :) http://stackoverflow.com/questions/1561803/android-progressdialog-show-crashes-with-getapplicationcontext – Soham Mar 06 '12 at 09:00
  • Magician is what you are! Worked like a charm. – Igor K. Mar 06 '12 at 09:16