In our opinion, both effects are the same, in fact, see the source code will know that cancel will definitely go to tune dismiss, if the call cancel the words can listen to Dialoginterface.oncancellistener.
/*** Cancel the dialog. This is essentially the same as calling {@link#dismiss ()}, but it would * also call your {@linkDialoginterface.oncancellistener} (if registered). */ Public voidCancel () {if(!mcanceled && Mcancelmessage! =NULL) {mcanceled=true; //obtain a new message so this dialog can be re-usedMessage.obtain (mcancelmessage). Sendtotarget (); } dismiss (); }
Dismiss can be called on any thread, but it is best not to overwrite the dismiss method, and it is necessary to override it in OnStop.
/** * Dismiss this dialog, removing it from th E screen. This method can is * invoked safely from any thread. Note that you should does cleanup when the dialog is dismissed, instead implement * th At { @link #onStop}. */ @Override public void dismiss () { if (Looper.mylooper () == Mhandler.getlooper ()) {dismissdialog (); else {Mhandler.post (mdismissactio n); } }
Called OnStop in DismissDialog.
voidDismissDialog () {if(Mdecor = =NULL|| !mshowing) { return; } if(mwindow.isdestroyed ()) {LOG.E (TAG,"Tried to DismissDialog () but the Dialog's window was already destroyed!"); return; } Try{mwindowmanager.removeviewimmediate (Mdecor); } finally { if(Mactionmode! =NULL) {mactionmode.finish (); } Mdecor=NULL; Mwindow.closeallpanels (); OnStop (); Mshowing=false; Senddismissmessage (); } }
Fill the Hide method, the note said hide just hide the dialog box and did not destroy, if you intend to use this method to extinguish the dialog box will be a problem, when the activity is destroyed when the crash log, because
When the activity is destroyed, it is necessary to shut down the dialog box.
The logs are as follows:
Android.view.WindowLeaked:Activity Com.example.androidtest_progressdialog. Mainactivity has leaked window Com.android.internal.policy.impl.phonewindow$decorview{434557e8 G.E ..... R..... ID 0,0-1026,288} That is originally added here
And look at what's in Hide:
/** * Hide The dialog, but does not dismiss it. */ Public void Hide () { ifnull) { mdecor.setvisibility (view.gone); } }
As you can see, hide simply sets the Decorview in the dialog box to be invisible and does not remove the Decorview from the window.
android dialog box dismiss and cancel and hide differences