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
Highlighted
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified
Accepted Solution

Capture keypress after Custom Menu in Message App is selected

I added a custom menu to the message app. It works great but I need to figure out how to capture user input of the ESC key after they clicked on my custom menu so i can clean up and terminate my library.

 

This is my custom menu code:

 

 

//Run is called when the menuItem is invoked public Object run(Object context) { //context object should be a email message if (context instanceof Message) { Call my library processor (mesage_data); } return context; }

 

 

 

Retired
Posts: 179
Registered: ‎07-14-2008
My Device: Not Specified

Re: Capture keypress after Custom Menu in Message App is selected

Tony,

 

I don't understand the question.  Any processing that is done within the ApplicationMenu item should be done either in the background or as part of your application running in the foreground (bring your application to be the visible main screen).  You should be able to detect the escape key if your application is showing UI and if you run entirely in the background you wouldn't have user interaction.

 

 

Mike Kirkup
Director, Developer Relations
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: Capture keypress after Custom Menu in Message App is selected

[ Edited ]

The flow of my program when the user selects my custom menuitem in the message app is as follows:

 

1. menuitem selected

2. read the contents of the message that is being viewed.

3. Start my shared library.

4. When shared library is up and running, display a dialog for user to proceed with processing or cancel

4a. Process and library close and clean up

4b. Close library and clean up

 

My problem is between steps 3 & 4.  while my library is being initialized i don't block user input so the user can press the ESC key and then I loose program control and I can not shut down my library and clear any resoruces.

 

I need to detect any irregular user imput so i can make sure to close my library as the message app always run in the background and this thread is left open.

 

Oh and yes my library is without UI. My alternate entry app has a UI because of displaying clipboard however its not displaying anything to user in the case of working with the message, memo, calendar, or ToDo.

 

I may have to use a timer to clean up if no processing event takes place after a preset time.

 

Edited by ipcTony on 12-16-2008 12:59 PM

Message Edited by ipcTony on 12-16-2008 01:28 PM
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Capture keypress after Custom Menu in Message App is selected

Tony, I think that you need to override deactivate() in your Application class - it is always called when the user switches out of your application for any reason.
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: Capture keypress after Custom Menu in Message App is selected

Thanks RexDoug. Read a little about deactivate() being called when my app is placed in the background. I'll try to figure out how to implement it in my app.
Retired
Posts: 179
Registered: ‎07-14-2008
My Device: Not Specified

Re: Capture keypress after Custom Menu in Message App is selected

Thanks for the clarification.

 

You will want to bring your application to the foreground immediately on running your code so that your application will receive any of the errant key inputs.  

 

Mike Kirkup
Director, Developer Relations
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: Capture keypress after Custom Menu in Message App is selected

Guys I'm hitting the wall on this.

 

I tried both methods adding code to bring my app up front to trap keypress or trying to catch the deactivate() that did not work.

 

I first added code in the class MailProcessMenu extends ApplicationMenuItem.

 

Then i tried to place code in my main class and this did not work. 

 

I guess I don't understand where the code should be place.

 

Sorry for not being a licensed programmer. I should stick to hardware...

 

Andy suggestions? 

Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: Capture keypress after Custom Menu in Message App is selected

Mike, Rex,

Thanks for the help on this. I found a solution by switching my program flow so that my dialog is presented to the user and in the background my library is being started. I guess this puts my application in the foreground so that keypress including ESC can be captured and clean up is then possible.

 

thanks again... this problem was a show stopper.