Recently discovered that if I wrote a message handling event in activity A's handler and then jumped from activity A to interface B, A's handler continues to process the message, and in my project, the user enters the room interface, starts receiving messages, Then he can also jump to the settings interface to do some room settings, if the user is forced to go out, regardless of the interface, all need to pop up a dialog box to show the user is kicked out, before the normal dialog, and then only the room screen display will be kicked out of the dialog box, This is not seen in the Setup interface and is then tested for bugs ... Always know to use window to do, but after trying to find the main problem is that one is to respond to the window's view above the button click event, one is the response system's back fallback event, either one does not respond, or can only respond to one, Looking for a long time on the internet did not find a good way. Finally, only a Boolean variable is added to enable the Back button to respond.
PrivateWindowManager Mwindowmanager =NULL; Private Booleanisshow; Privateview view; Public voidShowmsgwindow (String tipmessage, Context context) {Mwindowmanager=(WindowManager) Context.getsystemservice (Context.window_service); Windowmanager.layoutparams params=CreateParams (); View= View.inflate (Context, R.layout.window,NULL); TextView message=(TextView) View.findviewbyid (r.id.window_message); Button Cancel=(Button) View.findviewbyid (r.id.window_cancel); Button OK=(Button) View.findviewbyid (R.ID.WINDOW_OK); Message.settext (Tipmessage); Cancel.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {Removewindowmanager (); } }); Ok.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {Removewindowmanager (); } }); Mwindowmanager.addview (view, params); Isshow=true; } Public voidRemovewindowmanager () {Mwindowmanager.removeview (view); Isshow=false; } Publicwindowmanager.layoutparams CreateParams () {windowmanager.layoutparams params=NewWindowmanager.layoutparams (); //typeParams.type =WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; Params.flags= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; Params.format=pixelformat.translucent; Params.width=layoutparams.match_parent; Params.height=layoutparams.match_parent; Params.gravity=Gravity.center; returnparams; }
The method of activity @Override Public voidonbackpressed () {if(isshow) {Removewindowmanager (); } Else { Super. onbackpressed (); } }
More ugly, barely solved the problem.
Android pops up a window that appears on the desktop