Blackberry browser back click
Asked Answered
D

4

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;
}
Drabbet answered 25/10, 2010 at 13:24 Comment(2)
What class is the keyDown method a part of? Have you tried putting a debug printout or breakpoint there, to see if it gets executed?Ked
If you're still around please go through your questions and mark the correct answers as Accepted by ticking the empty V icons below their score. Thanks.Proctoscope
D
2

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

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

I hope it will be helpful.

Dissertate answered 25/10, 2012 at 17:24 Comment(0)
S
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();
        }   
    }
}
Stomato answered 28/12, 2011 at 13:40 Comment(0)
H
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);
    } 
}
Hymettus answered 2/4, 2012 at 6:39 Comment(0)
C
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 :)

Cockleboat answered 29/7, 2012 at 3:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.