开发者

Android spinner on dialog crashes if the spinner is open (list up) and you rotate the device

开发者 https://www.devze.com 2023-03-16 17:07 出处:网络
I have a Dialog with a couple of buttons and a spinner that seems to work fine except my app crashes under the following circumstances:

I have a Dialog with a couple of buttons and a spinner that seems to work fine except my app crashes under the following circumstances: 1. start activity 2. show dialog with Activity::showDialog (gets created in onCreateDialog) 3. click on the spinner so that it shows the list 4. spinner puts up an AlertDialog 5. rotate the device 6. crash with IllegalArgumentException

I can see that the Activity has gone away and also that my Dialog has gone away but the AlertDialog put up by the Spinner remains. I would just dismiss the Spinner AlertDialog but it is a private member of the Spinner class (I checked the Android source code) so there is no way to access it.

If you move the Spinner to the Activity you get: 1. start activity 2. click on spinner so that it shows the list 3. spinner puts up an AlertDialog 4. rotate the device 5. spinner AlertDialog disappears 6. activity is shown rotated

I can only conclude that either: 1. you are simply not supposed to put a spinner on an Dialog (or AlertDialog), or 2. there is a bug in Dialog or Activity

Does anyone has any 开发者_JAVA技巧wisdom on this issue?


In the manifest, add this to the declaration of your activity:

android:configChanges="orientation"


I had the same issue with PopupWindow. The solution is to call

popup.dismiss()

in the onDestroy() method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号