android dialog box dismiss and cancel and hide differences

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.