09-03-2012 11:55 AM
Hello i'm luis.
this is my code:
public class openWWW extends MainScreen {
boolean aFlag;
public openWWW(boolean hd) {
BrowserSession browser = Browser.getDefaultSession();
Browser.getDefaultSession().displayPage(webPage);
}
protected boolean keyDown(int keycode, int time) {
if (Keypad.key(keycode) == Keypad.KEY_ESCAPE) {
return false;
}
return false;
}
public boolean onClose() {
return false;
}
private void error(final String message) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert(message);
}
});
}
}
but when i press the escape button the app back to the previous Screen
what is the mistake?
09-03-2012 02:50 PM
Try overriding keyChar rather than keyDown. Works for me.
09-03-2012 11:50 PM
09-04-2012 01:09 AM
Use this code for escape key.
protected boolean keyChar(char c, int status, int time) {
try {
if (c == Characters.ESCAPE) {
synchronized (UiApplication.getEventLock()) {
// action for escape key
}
}
} catch (Exception ex) {
}
return super.keyChar(c, status, time);
}
09-04-2012 04:20 AM
Regarding the code provided by BrajeshSanodiya, because keyChar actually already runs on the Event Thread, there is no need to get the EventLock. You can run UI updating code in your keyChar method without needing to do any of the tricks.
In other words, the keyChar code provided could be simplified to:
protected boolean keyChar(char c, int status, int time) {
try {
if (c == Characters.ESCAPE) {
// action for escape key
return; // make sure super.keyChar is not invoked
}
} catch (Exception ex) {
}
return super.keyChar(c, status, time);
}