Yes, that's the "usual and customary" way of working with Android dialogs. You process the results in listeners, see the examples in dialogs guide or date picker dialog sample in the documentation.
When you create the dialog with an activity (you have to set proper theme of the activity), you can do the processing in listeners in the dialog activity. Or you can return the values to the parent activity and process them in onActivityResult callback.
The code you run in the listeners should be rather short and quick because it runs on the main thread. Never let the user wait! If the processing is time consuming do it in a the background.
One note to modal vs. non-modal (modeless) dialogs in Android. By default all the dialogs (and the activities displayed as dialogs) are modal. You can create modeless dialogs (and activities displayed as dialogs) by setting proper window flags (for more details see this question and answer).
发布评论
评论(1)
是的,这是使用 Android 对话框的“通常和习惯”方式。您可以在侦听器中处理结果,请参阅对话框指南中的示例或文档中的日期选择器对话框示例。
当您使用活动创建对话框时(您必须设置适当 活动的主题),您可以在对话框活动的侦听器中进行处理。或者,您可以将值返回到父活动并在
onActivityResult
回调中处理它们。您在侦听器中运行的代码应该相当短且快速,因为它在主线程上运行。永远不要让用户等待!如果处理很耗时,请在后台进行。
Android 中模态对话框与非模态对话框的注意事项。默认情况下,所有对话框(以及显示为对话框的活动)都是模态的。您可以通过设置适当的窗口标志来创建无模式对话框(以及显示为对话框的活动)(有关更多详细信息,请参阅此 问题和答案)。
Yes, that's the "usual and customary" way of working with Android dialogs. You process the results in listeners, see the examples in dialogs guide or date picker dialog sample in the documentation.
When you create the dialog with an activity (you have to set proper theme of the activity), you can do the processing in listeners in the dialog activity. Or you can return the values to the parent activity and process them in
onActivityResult
callback.The code you run in the listeners should be rather short and quick because it runs on the main thread. Never let the user wait! If the processing is time consuming do it in a the background.
One note to modal vs. non-modal (modeless) dialogs in Android. By default all the dialogs (and the activities displayed as dialogs) are modal. You can create modeless dialogs (and activities displayed as dialogs) by setting proper window flags (for more details see this question and answer).