I have my dialog based on AlertDialog.
When screen rotates (or some other config change happens), the dialog is closed by OS.
Problem is that my dialog plays audio by MediaPlayer, and when such auto-close happens, dialog is gone but sound continues to play.
Does Dialog get some chance to cleanup before it’s killed by system? Or I’m forced to use Activity in this case?
When screen rotates your Activity is destroyed and created new one.
If you have opened dialog and this dialog is not managed, it will leak. You can suppress this behaviour in manifest by defining
android:configChanges="orientation"for<activity>, then instead of recreating Activity anonConfigurationChangescallback is called instead. There you can handle screen rotation.If you are using
Activity.showDialog(int)then before activity is destroyed dialog states are saved. When new Activity is created saved information is used to restore your dialogs.Update
If you are looking for handling when your dialog is closed, you can use
AlertDialog.setOnDismissListener