gnoela
gnoela

Reputation: 3

Worklight initialization for Android always clears WebView history

I noticed cordovaInitCallback is called each time Worklight/Cordova is initialized in an Android app. In particular, it calls Cordova's "clearHistory" to wipe out the WebView history. This has been an issue when I try to make use of window.history in a multi-page app since the history is always reset during the initializtion from page to page.

Since the comment suggests that the purpose for this clearHistory call is to prevent going back to an old page in a direct update scenario, could the condition be strengthened over an Android environment check so that it is only called if a direct update has just taken place? One case, for example, I can think of is when connectOnStartup=false, then direct update would not occur.

wlclient.js:

 var cordovaInitCallback = function(returnedData) {
            onEnvInit(options);
            if (WL.Client.getEnvironment() == WL.Env.ANDROID) {
                if (returnedData !== null && returnedData !== "") {
                    WL.StaticAppProps.APP_VERSION = returnedData;
                }
                // In development mode, the application has a settings
                // widget in which the user may alter
                // the application's root url
                // and here the application reads this url, and replaces the
                // static prop
                // WL.StaticAppProps.WORKLIGHT_ROOT_URL
                // __setWLServerAddress for iOS is called within
                // wlgap.ios.js's wlCheckReachability
                // function because it is an asynchronous call.

                // Only in Android we should clear the history of the
                // WebView, otherwise when user will
                // press the back button after upgrade he will return to the
                // html page before the upgrade
                if (**WL.Env.ANDROID == getEnv()**) {
                    cordova.exec(null, null, 'Utils', 'clearHistory', []);
                }
            }

I am currently using Worklight 5.0.5, and have checked this same condition exists in 5.0.5.1.

Thanks!

Upvotes: 0

Views: 380

Answers (1)

Raanan Avidor
Raanan Avidor

Reputation: 3583

The architectural design of Worklight is SPA (Single Page Application).
cordovaInitCallback should be called only once in the life cycle of the application.
That said, you can, if you wish, override it.

Upvotes: 1

Related Questions