When I change device orientation, if AlertDialog was shown, it disappears. This is true for all but one dialogs in my app, and I can’t figure out neither what’s so special about the one that doesn’t disappear nor how to counteract this behaviour. Any possibility to preserve dialogs upon orientation change (except for manual management)?
When I change device orientation, if AlertDialog was shown, it disappears. This is true
Share
As suggested by many people here,
is not a solution. It’s a hack at best. The correct way to handle this is to manage dialogs through your activity. You need to override a few methods in your activity code, Like so:
After you’re done with this. You show your dialog using:
Once you’re done implementing this, your’ll see that your dialog will also be recreated if configuration changes occur. The best part is that your
Activitywill manage your dialog for you. It will be reused when possible, reducing dialog load times if you perform heavy initialization.