Android - How to Dismiss All Dialogs in onPause(Android - 如何在 onPause 中关闭所有对话框)
问题描述
我有一个活动可以在运行时显示不同的对话框.我使用 onCreateDialog(int id) 创建每个对话框,并使用 showDialog(int id) 和 dismissDialog(int id) 方法分别显示和关闭每个对话框.
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.
当 onPause() 被调用时,我不知道正在显示哪个对话框(如果有的话).我想确保在调用 onPause 时,所有对话框都被关闭.有没有推荐的方法来关闭所有对话框?我是否必须为每个对话框调用dismissDialog()?
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.
除了简单地在活动级别声明一些对话框之外,可能还有其他优雅的方法可以做到这一点.一旦声明它们,您可以将所有对话框存储在 HashMap 中,然后遍历列表并在暂停时关闭每个对话框.
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.
但是,如果您的屏幕上确实有这么多对话框,则您的 UI/UX 设计可能会出现一些问题,因为 Android 应该为您提供一个模型,该模型可以轻松实现它,而不会出现看似糟糕的设计.
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.
这篇关于Android - 如何在 onPause 中关闭所有对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android - 如何在 onPause 中关闭所有对话框
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01