Android Source Analysis Android toast using detailed toast customization

Source: Internet
Author: User

In the process of Android development, toasts make it a class that we often use when we need to communicate some information to the user, but it is a very appropriate way to do so without interacting with the user.

we are accustomed to using toast like this: Toast . Maketext (Context context, String info, int duration). Show (); This method is

The system provides us with a handy way to create a Toast object, and the inside of it is still the related method of invoking the toast to complete. Below

From its source code on the implementation of this class to do an analysis

In the Toast class, the most important show method for displaying the toast is called Service.enqueuetoast (pkg, TN, mduration);

The system maintains a toast queue for us, which is why two toasts are not displayed at the same time, and the method queues a toast, which is displayed by the The system maintains the timing of the display.

private static Inotificationmanager Sservice;

Static private Inotificationmanager GetService () {if (Sservice! = null) {return sservice;        } Sservice = INotificationManager.Stub.asInterface (Servicemanager.getservice ("Notification"));    return sservice; The service Sservice is the service that the system uses to maintain the toast.
Inside the toast is another static Private class TN, which is the main implementation of the toast, which completes the creation of the toast view, and so on


Fa

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.