Search code examples
blackberrybrowser-historybrowserfield

Editing a BrowserField's History


I have a BrowserField in my app, which works great. It intercept NavigationRequests to links on my website which go to external sites, and brings up a new windows to display those in the regular Browser, which also works great.

The problem I have is that if a user clicks a link to say "www.google.com", my app opens that up in a new browser, but also logs it into the BrowserHistory. So if they click back, away from google, they arrive back at my app, but then if they hit back again, the BrowserHistory would land them on the same page they were on (Because going back from Google doesn't move back in the history) I've tried to find a way to edit the BrowserField's BrowserHistory, but this doesn't seem possible. Short of creating my own class for logging the browsing history, is there anything I can do?

If I didn't do a good job explaining the problem, don't hesitate for clarification. Thanks


Solution

  • One possible solution to this problem would be to keep track of the last inner URL visited before the current NavigationRequest URL. You could then check to see whether the link clicked is an outside link, as you already do, and if it is call this method:

    updateHistory(String url, boolean isRedirect)
    

    with the last URL before the outside link. Using your example this should overwrite "www.google.com" with the last inner URL before the outside link was clicked.

    Here is some half pseudocode/half Java to illustrate my solution:

    BrowserFieldHistory history = browserField.getHistory():
    String lastInnerURL = "";
    if navigationRequest is an outside link {
        history.updateHistory(lastInnerURL, true);
        // Handle loading of outer website
    } else {
        lastInnerURL = navigationRequest;
        // Visit inner navigation request as normal
    }
    

    http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/browser/field2/BrowserFieldHistory.html#updateHistory(java.lang.String, boolean)