0

I'm seem to intermittently be getting the following error when I'm running my app.

"Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40521348 that was originally added here"

All I'm doing is creating my dialog in my onCreate() method like so:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

//Create splash-screen object and pass in width and height (width and height are defined and valid, I just removed them from this post to make it more readable)

    splash = new SplashScreen(MainActivity.this, width, height);

//Create dialog that will show splash-screen 
    loading_dialog = new Dialog(MainActivity.this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);

//Set and display splash screen view
    loading_dialog.setContentView(splash);
    loading_dialog.show();
}

Any ideas what the problem could be?

Zippy
  • 3,826
  • 5
  • 43
  • 96

3 Answers3

1

You can create dialog in onCreate but you can't show it, because activity is not visible yet. Google it, there was an example how to do it right somewhere...

Leonidos
  • 10,482
  • 2
  • 28
  • 37
0

I belive you need to create your dialog before showing it.

you need to do :

loading_dialog.create().show();

instead

loading_dialog.show();

I find Similar Q, you can use them

Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f72ff0 that was originally added here

Activity has leaked window that was originally added

Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@46029dd0 that was originally added here

Community
  • 1
  • 1
idan
  • 1,508
  • 5
  • 29
  • 60
  • Hey @idan, thanks but that doesn't work - there is no 'create()' method.... what I'm doing does work, the error is only intermittent! :-) – Zippy Jun 18 '13 at 22:31
0

It's probably because you don't cancel() your dialog before closing Activity. Try to do cancel() on your dialog in onStop() method. It should help. Hope it helps.

Pawel Cala
  • 685
  • 9
  • 14