Here is my problem.
I override volume down key for my application to do some specific task while it's pressed for a long time, it works fine normally. I can intercept key down and key up events for that.
The key listener events are written in particular custom component and not in activity where this component is used.
Problem arises when I press menu button while I have pressed the volume down key, and when I release it while menu is shown, I can not intercept its key up event.
Can you explain what is the reason behind it? And if this problem can be solved or not?
Thanks.
When Menu is clicked your window focus change. Focus come to Menu view. Because of this onKeyDown() does not work because onKeyDown wil work if the focus of the screen will be on the view or activity which is on top.
Use the following code to know focus of the screen
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
System.out.println("....window focus changed..");
super.onWindowFocusChanged(hasFocus);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With