What is difference between ` DialogInterface.dismiss()` and `DialogInterface.cancel()`? [duplicate]

蹲街弑〆低调 提交于 2019-12-21 03:34:18

问题


While working with dialogs in android one can cancel it or dismiss it, But when to use dismiss and when to use cancel? what is the difference between them? Thanks in advance.


回答1:


public void cancel () Since: API Level 1

Cancel the dialog. This is essentially the same as calling dismiss(), but it will also call your DialogInterface.OnCancelListener (if registered).

This is what docs says, Both are same, just cancel() will call the listener registered on DialogInterface.

Reference link
see this ANSWER too for reference




回答2:


cancel() - Cancel the dialog. This is essentially the same as calling dismiss(), but it will also call your DialogInterface.OnCancelListener (if registered).

dismiss() - Dismiss this dialog, removing it from the screen. This method can be invoked safely from any thread. Note that you should not override this method to do cleanup when the dialog is dismissed, instead implement that in onStop().

You should check here for more info how to use this two methods



来源:https://stackoverflow.com/questions/12139335/what-is-difference-between-dialoginterface-dismiss-and-dialoginterface-can

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!