Android fix toast has been showing a constant problem

Source: Internet
Author: User

The most commonly used pop-up when doing a program is probably toast. But sometimes a particularly embarrassing question is: Once you click on a button a lot more times, even after the program exits, the toast will not stop. What causes it?

This is the case: for convenience, we usually use Toast.maketext (this, "Toast test", Toast.length_long) when writing pop-up toast. Show ();. Popping a toast too much is exactly what happens in the code itself. Because each call to this code program will recreate a Toast object (Tost popup order is one after the other, that is, the first from the display to disappear, the second to be able to display). The result is that the toast pop-up time accumulates, resulting in a pop-up phenomenon.

Workaround: Quite simply, the above is not mentioned because of the cause of creating a new object each time. Then we don't give it a chance to create other objects. Write a custom toast with a singleton. Problems can be solved. Single case I believe everyone will, here I will not repeat, only provide a reference idea.

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.