Biribu
Biribu

Reputation: 3823

Modifying behavior back button in blackberry OS5-7 BrowserField

I am developing an app in php and html for showing inside a BrowserField in blackberry. I want that when the user press the back buttonm the app goes back or just go to the index webpage.

Now, whenever you press it, app closes.

Any idea?

Upvotes: 0

Views: 113

Answers (1)

Peter Strange
Peter Strange

Reputation: 2650

I'm going to assume that you are displaying a BrowserField inside a MainScreen.

And I presume what you are calling the "back button" the key that would normally be referred to as the "ESC button". The normal behaviour of the "ESC button" is to close the current screen, and if that is your only screen, this can close your application.

To restrict this behaviour, you can override the MainScreen method keyChar(), which is what I expect most people do. Instead of closing the screen, I suspect most applications will attempt to 'go back' as far as the BrowserField is concerned. Code which should do this is included below (I say should because I have not compiled or tested this code).

protected boolean keyChar(char character, int status, int time) {
 switch (character) {
  case Characters.ESCAPE:
   if ( browserField.getHistory().canGoBack() ) {
    browserField.back();
   } else {
    close();
   }
   return true;
  default:
   return super.keyChar(character, status, time);
 }
}

Upvotes: 2

Related Questions