I have an activity that could show different dialogs during run-time. I use onCreateDialog(int id) to create each dialog and I use showDialog(int id) and dismissDialog(int id) method show and dismiss each dialog respectively.
When onPause() is called, I don’t know which dialog (if any) is being displayed. I want to make sure that when onPause is called, all dialogs are dimissed. Is there a recommended way to dismiss all dialogs? Would I have to call dismissDialog() for each dialog?
Depending on how many dialog’s we’re talking about. The short answer is yes, you’ll have to dismiss each dialog.
There may be elegant ways of doing this other than simply having a few dialogs declared at the activity level. You could store all the dialogs in a HashMap once they are declared and then iterate through the list and close each one onPause.
Since you don’t know which are open you’ll need to go through and test or track the states.
However, if you truly have this many dialogs on your screen you may have some issues with your UI/UX design as Android should give you a model which makes it easy to implement it without what seems like poor design.