iOS App freezes when calling setURL in BrowserNavigationCallback

27 views
Skip to first unread message

appse...@gmail.com

unread,
Jun 6, 2014, 11:38:22 AM6/6/14
to codenameone...@googlegroups.com
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Device: iPhone 5

Hi,
there seems to be something wrong with the BrowserNavigationCallback/BrowserComponent.setUrl implementation on iOS.
My BrowserNavigationCallback is checking every URL for a few specific request parameters. If the request parameters are not set it modifies the url and calls setUrl again, while returning false, otherwise it returns true.
Here is a basic implementation which works fine on the Simulator and Android, but "freezes" on iOS.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form callbackForm = new Form();
    callbackForm.setLayout(new BorderLayout());
    final WebBrowser myWebBrowser = new WebBrowser();
    myWebBrowser.setURL("http://www.example.com");
    if (myWebBrowser.getInternal() instanceof BrowserComponent) {
        ((BrowserComponent) myWebBrowser.getInternal()).setBrowserNavigationCallback(new BrowserNavigationCallback() {

            public boolean shouldNavigate(final String url) {
                if (url.indexOf("callback=true") != -1) {
                    return true;
                }
                myWebBrowser.setURL(appendRequestParameter(url, "callback=true"));
                return false;
            }

            private String appendRequestParameter(String url, String parameter) {
                return url.concat(((url.lastIndexOf("?") == -1) ? "?" : "&") + parameter);
            }
        });
    }
    callbackForm.addComponent(BorderLayout.CENTER, myWebBrowser);
    callbackForm.show();
}


Thanks in advance

Steve Hannah

unread,
Jun 6, 2014, 12:19:50 PM6/6/14
to codenameone...@googlegroups.com
The browser navigation callback's shouldNavigate() method does not run on the EDT, so your call to myWebBrowser.setURL() could be causing a deadlock, race condition, or infinite recursion.

Try wrapping your setURL() call inside Display.callSerially() so that it runs on the EDT.

Also be aware of the possibility that you are just simply causing an infinite loop because the call to myWebBrowser.setURL() may trigger the browser navigation callback, which calls setURL(), which calls... etc...

Steve


--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/199c49a1-30ce-4849-870b-e20f6539f0b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Web Lite Solutions Corp.
Reply all
Reply to author
Forward
0 new messages