I have an activity which inflates a listview. On list item click a dialog is opened(it is handled in the corresponding list adapter.) On orientation change the showing dialog (if any) is disappeared (as expected.) What I want is the showing dialog not to dismiss on orientation change and I don't have an idea how to cleanly handle it.
Asked
Active
Viewed 2,834 times
1
-
you cant handle, unless you want to give up change of orientation support to your application. – Techfist Aug 18 '14 at 06:19
2 Answers
1
When you rotate the phone, your activity is actually destroyed and recreated. This includes your dialog. Yes, its quite possibly the stupidest design decision in history, but we're stuck with it. There are two ways to fix it:
1) Turn off this "helpful" functionality. If you don't have different layouts for landscape and portrait its what I'd suggest. Add android:configChange="orientation|resize" to your activity in the manifest.
2) Implement onSaveInstanceState/onRestoreInstanceState and have a variable that says whether or not you need to recreate and relaunch the dialog.

Paresh Mayani
- 127,700
- 71
- 241
- 295

Gabe Sechan
- 90,003
- 9
- 87
- 127
0
You can disable the orientation changing in the androidManifest.xml file
<activity
android:name="com.example.deneme"
android:label="@string/app_name"
android:launchMode="singleTop"
*************android:screenOrientation="landscape" >*******************
</activity>
OR
you can do it before dialog is show
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
after dialog is show
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

fatih inan
- 144
- 1
- 6