Dialog는 안드로이드에서 자주 사용되는 UI 컴퍼넌트이지요..
그런데, Dialog를 show()하고 종료하기 위해서, cancel(), dismiss()를 사용할 수 있는데요..
API 문서에서는 아래와 같이 설명을 하고 있습니다.. 제가 UI쪽은 거의 안해봐서 그런가? 동작하는게 똑 같아 보입니다..


void cancel()
Cancel the dialog.

void dismiss()
Dismiss this dialog, removing it from the screen.


흠.. 몬 차이가 있을까요??
소스에 자세한 설명이 있네요.. 젠장..^^;;

아래 canel() 메소드를 호출하면 mCancelMessage가 있으면 보내주고, dismiss()를 호출하는 구조이고, onCancelListener에서 선언한 메소드를 호출해 준다고..

Cancel the dialog. This is essentially the same as calling dismiss(), but it will also call yourandroid.content.DialogInterface.OnCancelListener (if registered).
 
     public void cancel() {
         if ( != null) {
             
             // Obtain a new message so this dialog can be re-used
             Message.obtain().sendToTarget();
         }
         dismiss();
     }


아래 dismiss()메소드는 스크린에서 dialog를 제거하는데 쓰레드 세이프 하다네요..

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().
 
     public void dismiss() {
         if (Thread.currentThread() != ) {
             .post();
         } else {
             .run();
         }
     }


흠.. API 문서를 봐서 잘 이해가 안되는 메소드는 역시, 소스를 살펴봐야 됩니다..
역시 소스에 답이 있다는 진리는 변하지가 않는 것 같습니다.. ^^


저작자 표시