Custom toast, toast exited when the program exits, and toast usage

Source: Internet
Author: User



When we use toaster as a prompt in an application, we find such a problem. When a condition server is used, the toaster dialog box will pop up and this condition will be executed continuously, toaster will not stop. show: the display is displayed several times after execution. Even if the application exits, the toast will not stop. show, this will bring a poor user experience. When we exit the application, we should not display toast. Show.

We can implement toaster. Cancel () when the application exits ondestroy (), but toaster must be global, the same toaster

[Java] View plaincopyprint?
  1. Mtoast = new toast (this); // oncreate ()
  2. Layoutinflater Inflater = layoutinflater. From (this );
  3. View view2 = Inflater. Inflate (R. layout. toAs, null );
  4. Mtoast. setview (view2 );
  5. Mtoast. setduration (1000 );
  6. Create a layoutinflater, which includes:
  7. <Linearlayout xmlns: Android = ""
  8. Android: Orientation = "vertical" Android: layout_width = "wrap_content"
  9. Android: layout_height = "wrap_content">
  10. <Textview Android: layout_width = "wrap_content"
  11. Android: Background = "# ff000000"
  12. Android: layout_height = "wrap_content" Android: text = "@ string/most_char"/>
  13. </Linearlayout>


You can control toaster. Show by following the preceding steps.

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: 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.