4

I have been working on a hybrid android application. Currently a WebView in our application is pointing to an AngularJS 1.5.7 application. When the user hits a button inside of the application that changes the route I was expecting the shouldOverrideUrlLoading function to be called inside of my WebViewClient. However, this is not the case. It looks like shouldOverrideUrlLoading does not get hit on Angualar route changes.

This being the case I have gone down the following rabbit holes:

  1. onPageFinished - Overriding this function in the WebViewClient works, however, it is not being called until after the new route is getting hit. Which is adding to the application loading time and creating a choppy experience. ` @Override public void onPageFinished(WebView view, String url) {

            if (url.endsWith("/#/")) {
                signOut();
            } else if (url.endsWith("/login")) {
                // TODO: show some sort of failure message?
                Log.i("Login Route", "The webview just attempted to go to the login route.");
                signOut();
            } else if (url.endsWith("/security")) {
                Intent intent = new Intent(getApplicationContext(), SecurityActivity.class);
                startActivity(intent);
            }
        }`
    
  2. shouldInterceptRequest - Overriding this function allows you to watch for requests. However, by the time the requests go out from the AngularJS application the web view is showing a new route once again providing a choppy user experience.

  3. onLoadResource - same

  4. JavaScriptInterface - Currently I have set up a JavaScript interface to watch for window.location changes. This seems to catch the route changes quicker than any of the above options, however, there is still a glimpse quick flicker of the web page I do not want to do go to. You can find how to do Javascript bridging on this post

Any suggestions would be greatly appreciated! Thanks.

  • You could use `doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean)` from `WebViewClient`, but this has the same problem you mention in your point 4. Still, you won't have any changes on your JS side. – jayearn Feb 08 '19 at 15:45
  • How to solve this? – Tristate Feb 22 '20 at 14:43

0 Answers0