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;
}
to return to the previous page you may try the following:
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
I hope it will be helpful.
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();
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With