Tuesday, 15 September 2015

Android Dialog dismiss using handler -


I get a stranger question when I read the Android Global Action source code, I think it starts a dialogue Will, but add a justice that will judge whether this dialogue has been shown, if it was shown earlier, it will be rejected and then show it. Strangers thing is that to dismiss the dialogue, again, I do not understand why it is necessary to send a handler message, I think it just dismisses the dialogue. Then call is called a function, this is not a problem. The comment said: "Look at the delay, so that the last dialogue is completed by rejecting", but I also can not understand the meaning, please help me to help someone please, thank you very much.

  if (mDialog! = Null) {mDialog.dismiss (); MDialog = null; // appear delayed, so that mHandler.sendEmptyMessage is completed by rejecting the previous dialog (MESSAGE_SHOW); } Many Android UI functions apply themselves using messages, and therefore Are not immediately completed. When you call  Dialog.dismiss () , then Android gives a message that actually damages. The author of this code wants to ensure that the dialogue is actually dismissed before showing it, and so he posts his message, which will not run until after the Android has posted.   

No comments:

Post a Comment