It is found that there is a problem with the system's toast cancel mechanism. Once the previous cancel is removed and a new toast is displayed, the new toast will be stuck for a period of time and cannot be displayed.
Note the following when creating a toast system:
1. Create a service dedicated to display, hide, etc.
2. Use addview and removeview of windowmanager in the service for display and hide
3. Pay attention to the flag, format, type, and other parameters to be set.
4. Add the following permissions to androidmanifest. xml:
<Uses-Permission Android: Name = "android. Permission. system_alert_window"/>
Without this permission, the focus of the current window of the system will be taken away.
KeyCodeAs follows:
Public void show (context, string content) {windowmanager = (windowmanager) Context. getsystemservice (context. window_service); If (TV! = NULL) {windowmanager. removeview (TV);} windowmanager. layoutparams Params = new windowmanager. layoutparams (); Params. height = windowmanager. layoutparams. wrap_content; Params. width = windowmanager. layoutparams. wrap_content; Params. Y + = 20; Params. flags = windowmanager. layoutparams. flag_not_focusable | windowmanager. layoutparams. flag_not_touchable; Params. format = pixelformat. translucent; Params. type = windowmanager. layoutparams. type_toast; layoutinflater = (layoutinflater) context. getsystemservice (context. layout_inflater_service); TV = (textview) layoutinflater. inflate (R. layout. renren_toast, null); TV. settext (content); windowmanager. addview (TV, Params );}
Supplement: 2011.11.18
After finding the solution, you can directly take the original toast and reset the display text and time.