Reputation:
I'm making an app in which I open a BrowserField
and the user can navigate further to links present in the web page. The problem is that when I press the physical back button, the previous screen is presented while I want to present the previous page in the BrowserField
itself. How to do that? Is that even possible?
Thanks.
Upvotes: 1
Views: 1713
Reputation: 3726
Yes It is Possible.
Try this code:
public class NewsBrowserScreen extends MainScreen
{
int current_index,popup;
String url;
VerticalFieldManager vertical;
BrowserField browserField;
BrowserFieldConfig browserFieldConfig;
BrowserFieldHistory browserFieldHistory;
public NewsBrowserScreen(int current_index,int popup,String url)
{
this.current_index=current_index;
this.popup=popup;
this.url=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();
}
}
}
Enough;
Upvotes: 1
Reputation: 7644
You need to use BrowserFieldHistory
to go back to previous pages using the canGoBack()
and goBack()
methods. Just over-ride the keyChar
method to control the ESCAPE
key input and put your own logic like so:
public boolean keyChar(char key, int status, int time) {
if ( key == Characters.ESCAPE) {
if(yourBrowserField.getHistory().canGoBack()){
yourBrowserField.getHistory().goBack();
}else{
UiApplication.getUiApplication().popScreen(this);
return true;
}
}
}
Upvotes: 2