Android Toast and androidtoast
Reprinted please indicate the source: http://blog.csdn.net/droyon/article/details/42009015
We can use the toast control provided by androd. However, during the use process, we send a large number of Toast requests and find that Toast will be sent continuously. Even if we exit the application interface, Toast is still not stopped.
We can understand the cause of this situation with a slight analysis. Here we provide a way to avoid this situation:
First, encapsulate the ToastMaster class:
static class ToastMaster { private static Toast sToast = null; private ToastMaster() { } public static void setToast(Toast toast) { if (sToast != null) sToast.cancel(); sToast = toast; } public static void cancelToast() { if (sToast != null) sToast.cancel(); sToast = null; } }
Then, in the specific use process:
Toast toast = Toast.makeText(context, toastText, Toast.LENGTH_LONG); ToastMaster.setToast(toast); toast.show();
Finally, execute the following code when exiting the interface:
LeUINotificationsUtils.ToastMaster.cancelToast();
If you have any children's shoes, you can refer to the above method for optimization.