In my app i am using DialogFragment to show a dialog for some seconds, now when i change my device's screen orientation, app crashes because the context i am using in my Dialog fragment goes null. After searching i found that in my activity's onDestroy() method i should dismiss that dialog if it is already showing so that my app doesn't crash. Now i need to get that dialog that is showing how i can get it? so that i can implement a check on it Any suggestions will be appreciated
Asked
Active
Viewed 365 times
1
-
1https://stackoverflow.com/questions/3329318/android-how-to-not-destroy-the-activity-when-i-rotate-the-device – vikash kumar pandey Jun 22 '17 at 05:26
-
You can handle it by overriding `onConfigurationChanged` https://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange .This will avoid the activity to get restarted again and hence context will not become null. – Sunil Sunny Jun 22 '17 at 05:44
-
@vikashkumarpandey thats for the link it worked – User Jun 23 '17 at 02:59
1 Answers
2
add in your menifest file
"android:configChanges="orientation|screenSize"
in the actvity tag like below :
<activity
android:name=".activities.HistoryDefectDetail"
android:configChanges="orientation|screenSize" />

Arun kumar
- 1,894
- 3
- 22
- 28