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
New Developer
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Regarding onClose() of MainScreen

hi,

does anybody know how to determine if the user clicked the "return" key or the "close" menu without using a keypad listener?

i believe the onClose() method will be executed on both scenarios since the MainScreen will be closed.

i tried using a KeypadListener, and it worked well in the simulator. but when i transferred my application to the device, i was thrown an exception that says: Unauthorized attempt to monitor key presses.

Do you have any suggestions on what i should do to solve this problem?

jacy
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Regarding onClose() of MainScreen

It can't be done without a KeypadListener .. By the way, are you sure, have you set allow in the application permissions?

 

Thanks! 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Regarding onClose() of MainScreen

Hi,

 

 

Instead of using keypadListener try using

 

 protected boolean keyChar(char key, int status, int time) this method try to trap event when value of key is 27

 

protected boolean keyChar(char key, int status, int time){ if (key == Characters.ENTER){ return true; // We've consumed the event. }else if(key == (char)27 && screenNo==1){ CTIAMain.saveData(); int result = Dialog.ask(Dialog.D_YES_NO,"Are you sure you want to exit ?"); if(result == Dialog.YES) System.exit(0); return true; } return super.keyChar(key, status, time); }

 

This will help you in solving your issue.

 

Please letme know whether it helped you or not

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Regarding onClose() of MainScreen

@ Rajat_10Sep .. However that method is present in KeyListener right?

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Regarding onClose() of MainScreen

Hi,

 

As mainscreen implements key events we should not implement it again.

 

I read that in the forum some where try to post the link of that thread.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Regarding onClose() of MainScreen

Thanks for reminding it :smileytongue:
--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group