Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 41
Registered: ‎08-11-2010
My Device: BlackBerry Simulator
Accepted Solution

onClose Back Button

Hi  friends

 

I wanted to know whether onClose() is called by default when we press back /  escape button. This is a very strange problem for me as this was not happening few days back. Although some time back I messed up my code by implementing Key Listener since I wanted to close the screen when escape is pressed. Now I have removed KeyListener from my code but its effect still remains. I have kept onClose since I want the user to go out he presses a button.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: onClose Back Button

The framework will call onClose() in response to the escape key if the screen has the DEFAULT_CLOSE style bit set. For the escape key to work, you need to include DEFAULT_CLOSE whenever you explicitly set the style for your screen.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Contributor
Posts: 41
Registered: ‎08-11-2010
My Device: BlackBerry Simulator

Re: onClose Back Button

@Ted_Hopp: Thanks for your reply. What value should I provide so that ESC executes normally and doesnt call onClose.

 

public static final long DEFAULT_CLOSE
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: onClose Back Button

I was talking about Screen.DEFAULT_CLOSE. However, I read your initial post incorrectly. You should specify a style that does not include DEFAULT_CLOSE.

 

An alternative (and probably better) way is to override onClose(). Put your logic there about when to close the screen and when to do something else. (I think users usually expect the ESC key to work like a "back" button. You should think carefully about the wisdom of changing this.)




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Contributor
Posts: 41
Registered: ‎08-11-2010
My Device: BlackBerry Simulator

Re: onClose Back Button

@Ted_Hopp: onClose was being called by default. I have moved the logic to some button and onClose works normally; the way I wanted it to work.