During the Android development process. Toasts make it a class that we often use. When we need to communicate some information to the user, but it is not necessary to interact with the user, this approach is a very appropriate way.
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 convenient static method for creating toast objects, and the inside is still the relevant method of invoking the toast. Following
From its source code to 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. This method will queue a toast and display the time that the system maintains 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
Android source code analytics Android toast using specific explanation toast yourself definition