Reputation: 181
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;
}
Upvotes: 10
Views: 883
Reputation: 2467
to return to the previous page you may try the following:
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
I hope it will be helpful.
Upvotes: 2
Reputation: 6610
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 :)
Upvotes: 0
Reputation: 2701
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);
}
}
Upvotes: 0
Reputation: 2862
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();
}
}
}
Upvotes: 1