Android Toast and androidtoast

Source: Internet
Author: User

Android Toast and androidtoast

Reprinted please indicate the source: http://blog.csdn.net/droyon/article/details/42009015


We can use the toast control provided by androd. However, during the use process, we send a large number of Toast requests and find that Toast will be sent continuously. Even if we exit the application interface, Toast is still not stopped.

We can understand the cause of this situation with a slight analysis. Here we provide a way to avoid this situation:

First, encapsulate the ToastMaster class:

static class ToastMaster {        private static Toast sToast = null;        private ToastMaster() {        }        public static void setToast(Toast toast) {            if (sToast != null)                sToast.cancel();            sToast = toast;        }        public static void cancelToast() {            if (sToast != null)                sToast.cancel();            sToast = null;        }    }

Then, in the specific use process:

Toast toast = Toast.makeText(context, toastText, Toast.LENGTH_LONG);        ToastMaster.setToast(toast);        toast.show();

Finally, execute the following code when exiting the interface:

LeUINotificationsUtils.ToastMaster.cancelToast();

If you have any children's shoes, you can refer to the above method for optimization.


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.