If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified
My Carrier: Vodafone

thread wait for key pressed

Hello,

 

I think I'm thinking to complicated at the moment!

 

I don't know how I can awake a sleeping thread when a key is pressed! :smileysad:

 

The following situation:

 

I have a thread which try to get a HttpConnection, when something goes wrong, the thread push a Dialog, and know I want to wait til the user press the ok Button. How can I implement this?

 

something from my code:

 

 

}catch (final IOException ex) {
  synchronized (UiApplication.getEventLock()) {
    UiEngine ui = Ui.getUiEngine();
    Dialog dia = new Dialog(Dialog.D_OK, "text", Dialog.OK, 
                 Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 
                 PopupScreen.NO_VERTICAL_SCROLL);
    ui.pushScreen(dia);
				
    //wait for key pressed

    int result = dia.getSelectedValue();
    
    if(result == Dialog.OK){
	//do something
  }
}

 

 

Any ideas?

 

Regards

 

Please use plain text.
Developer
simon_hain
Posts: 15,908
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: thread wait for key pressed

usually you use wait and notify for this. if your IO throws an ioexception you'll have to restart your communication anyhow.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified
My Carrier: Vodafone

Re: thread wait for key pressed

yeah I know that I have to restart the communication.

 

But my problem is, how I can implement the KeyListener because it is only a popupscreen, do I have to write a new Class extend PopUpScreen and override there the keychar() method?

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: thread wait for key pressed

You can do it without going through the hurdle of creating a new class.  Your "Dialog dia = ..." might look like this:

 

Dialog dia = new Dialog(Dialog.D_OK, "text", Dialog.OK, 
                 Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 
                 PopupScreen.NO_VERTICAL_SCROLL) {
    protected boolean keyChar(char ch, int status, int time) {
        <object>.notifyAll();
        return super.keyChar(ch, status, time);
    }
};
ui.pushScreen(dia);

...

 

 

Hope that helps,

    Arkady.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
wpbbmg
Posts: 83
Registered: ‎02-19-2010
My Device: Not Specified
My Carrier: Vodafone

Re: thread wait for key pressed

Is it possible that the method will never invoke? I test it with a println and with another dialog and nothing was shown, so I think when I press a key keychar() will not invoke, is it possible?

Please use plain text.