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