Android pops up a window that appears on the desktop

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.