10

I am trying to go back back to the previous page after loading a browser but it takes three back clicks to do so. I tried overriding the back button click but it still takes three clicks. I used following code to load the browser:

BrowserSession browserSession;
browserSession = Browser.getDefaultSession();
try{
   browserSession.displayPage(mapLocation);
}catch(Exception e){
   e.printStackTrace();
}

EDIT copied from answer by user:

I want to go to the previous screen not the previous page in the browser. The code for the back button :

protected boolean keyDown(int keycode, int status) {
  if(Keypad.key(keycode) == Keypad.KEY_ESCAPE) {
      _theApp.popScreen(this);
      return true;
  }
  return false;
}
Shadow The Vaccinated Wizard
  • 62,584
  • 26
  • 129
  • 194
user486464
  • 181
  • 5

4 Answers4

2

to return to the previous page you may try the following:

UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());

I hope it will be helpful.

Gaston Flores
  • 2,357
  • 1
  • 19
  • 40
1

This is the solution for back when you click on back(ESC) then it will help you Note:Available os5.0 later

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.browser.field2.BrowserFieldConfig;
import net.rim.device.api.browser.field2.BrowserFieldHistory;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class NewsBrowserScreen extends MainScreen 
{

    String url="http://stackoverflow.com";
    VerticalFieldManager vertical;
    BrowserField browserField;
    BrowserFieldConfig browserFieldConfig;
    BrowserFieldHistory browserFieldHistory;
//  BrowserSession browserSession;

    public NewsBrowserScreen(int current_index,int popup,String url) 
    {
        createGUI();
    }
    private void createGUI()    
    {       
        vertical=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR|HORIZONTAL_SCROLL|HORIZONTAL_SCROLLBAR);
        browserFieldConfig=new BrowserFieldConfig();
        browserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);     
        browserField=new BrowserField(browserFieldConfig);
        browserFieldHistory=browserField.getHistory();
        vertical.add(browserField);
        add(vertical);
        browserField.requestContent(url);
    }
    public boolean onClose() 
    {
        if(browserFieldHistory.canGoBack())
        {
            browserFieldHistory.goBack();           
            return true;
        }
        else
        {
            browserFieldHistory.clearHistory();
            return super.onClose();
        }   
    }
}
Govindarao Kondala
  • 2,872
  • 14
  • 27
0

every time you do something, try to update currentLayoutState and previousLayoutState (add those vars to your app) then override onBackPressed() if on android or onKeyPress() if not and try to transition to previousState if it's different from current state.

i'm guessing you're keeping track of states somewhere, right?

EDIT: i see it's not about states. shouldn't make much difference though, i hope you get the idea :)

Shark
  • 5,787
  • 3
  • 21
  • 46
0

Code is as follows

protected boolean keyDown(int keycode, int time)
{
    ////keycode for back button
    if(keycode == 1769472)
    {
        UiApplication.getUiApplication.popscreen();
        return true;
    }
    else
    {
        return super.keyDown(keycode, time);
    } 
}
Shadow The Vaccinated Wizard
  • 62,584
  • 26
  • 129
  • 194
Ved
  • 2,679
  • 1
  • 20
  • 30