2017-06-22 22 views
1

在我的應用程序中,我使用DialogFragment顯示幾秒鐘的對話框,現在當我更改設備的屏幕方向時,應用程序崩潰,因爲我在對話框片段中使用的上下文變爲空。 搜索後,我發現在我的活動onDestroy()方法我應該消除該對話框,如果它已經顯示,以便我的應用程序不會崩潰。 現在我需要得到那個對話框,展示我如何得到它?這樣我可以在其上實現 檢查任何建議將理解如何獲得使用DialogFragment附加的對話框? [ANDROID]

+1

https://開頭計算器。 com/questions/3329318/android-how-to-not-destroy-the-activity-when-i-rotate-the-device –

+0

你可以通過覆蓋'onConfigurationChanged'來處理它https://developer.android.com/guide /topics/resources/runtime-changes.html#HandlingTheChange。這將避免活動再次重新啓動,因此上下文不會變爲空。 –

+0

@vikashkumarpandey多數民衆贊成它的工作鏈接 – User

回答

2

添加在您的menifest文件

"android:configChanges="orientation|screenSize" 

在actvity標籤象下面這樣:

<activity 
      android:name=".activities.HistoryDefectDetail" 
      android:configChanges="orientation|screenSize" /> 
+0

謝謝它工作:) – User

相關問題