2013-06-18 48 views
0

我似乎在運行我的應用程序時間歇性地出現以下錯誤。在onCreate方法中創建一個對話框 - 泄漏

「活動已經泄露,最初這裏添加窗口[email protected]

我做的,我的onCreate()方法就像是創造我的對話所以:

@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(); 
} 

任何想法是什麼問題可能是?

回答

0

我相信你需要在顯示它之前創建對話框。

你需要做的:

loading_dialog.create().show(); 

代替

loading_dialog.show(); 

我找到類似的Q,你可以用它們

Activity has leaked window [email protected] that was originally added here

Activity has leaked window that was originally added

Activity has leaked window [email protected] that was originally added here

+0

嗨@idan,謝謝,但不起作用 - 沒有'create()'方法....我正在做的工作,錯誤只是間歇性的! :-) – Zippy

+1

我添加了類似Q的鏈接,我希望它能幫助你... – idan

1

您可以在onCreate中創建對話框,但無法顯示它,因爲活動尚不可見。谷歌它,有一個例子如何做到這一點正確的地方...

0

這可能是因爲你沒有取消()之前關閉活動對話框。 嘗試在onStop()方法的對話框中執行cancel()。它應該有所幫助。 希望它有幫助。