I've written an IME that displays some popup windows and closes them when the user clicks Back. It works 99% of the time but some apps (like Browser) are able to intercept the KeyEvent.KEYCODE_BACK
before my IME, leaving 开发者_StackOverflow社区my popup window stuck open.
According to the docs InputMethodService should receive key events before Activity. I've tested this with an Activity and it works as expected.
I checked the Browser source code and it simply overrides Activity.onKeyDown()
and onKeyUp()
, which should receive events after InputMethodService.onKeyDown()
and onKeyUp()
.
Why does the browser seem to receive key events in the wrong order? Please help because I don't want to have to add ugly close buttons to all my popups!!!
Thanks in advance,
Barry
Its Activity.onBackPressed(). Be careful when you override the functionality of this button as it can create a very negative user experience if you're doing something unexpected or completely ignoring the back button.
If you're using AlertDialogs or similar for popups you may not need to override the functionality, just setCancelable(true). Touching the screen and the back button will close the dialog.
精彩评论