app crashes when alert dialog is open and phone(emulator) changes its orientation

做~自己de王妃 提交于 2019-12-03 22:45:00

Are you using progressDialog.show() and progressbarDialog.dismiss() in the AyncTask?

If yes try using showDialog(id) and dismissDialog(id) in the AyncTask instead of it. You will have to write custom dialog in the onCreateDialog() for showing the loading dialog. showDialog and dismissDialog methods are activity level methods. I mean they are invoked on the Activity or its Context. So even if the activity is recreated after orientation change, latest context will be made available for the Dialog.

check for Sample code here. Modify DIALOG_PROGRESS case in it as per your requirement.

Also, onRetainNonConfigurationInstance() works perfectly with the orientation change. It just that due to window leak problem you are not able to see it.

By default your Activity is destroyed and recreated when the orientation changes. You can turn this off, and handing this configuration change on your own by setting the configChanges attribute.

You can either disable configuration changes, that is to say, you can stop the application from trying to redraw once the orientation of the phone changes by using XML in your Manifest file:

<activity android:name=".Main" 
 android:label="@string/app_name"
 android:screenOrientation="portrait" 
 android:configChanges="orientation|keyboardHidden">

When the orientation of your phone changes, by default Android will try and re-instantiate your page.

Bandzio

I had very similar issue, i resolve it with little change in manifest acitivity attr. From: android:configChanges="orientation" To: android:configChanges="keyboardHidden|orientation"

see here : Spinner drop-down list and screen orientation change problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!