简体   繁体   中英

Cordova splash screen hangs during asynchronous request

I'm building a Cordova app and we're practically finished except for the fact that the app is performing poorly under a certain condition. Under this condition, a series of asynchronous ajax calls (amounting to about 15 seconds by the time the responses are received) are made. These calls should be made once the page is already loaded and displayed. Thus, they are made in the onpageshow function of the landing page. The issue is that the Cordova splash screen stays up until the call is complete. My only theory right now is that Cordova won't kill the splash screen until the network is quiet. Does anyone have any idea how I can get Cordova to ignore these server calls? I attempted calling cordova.exec(null, null, "SplashScreen", "hide", []) on deviceready, but that didn't seem to get it to go away. If it's relevant, this same exact server call runs asynchronously just fine when it's invoked while already in the app and the user is none the wiser. The issue seems to be solely on app load.

Thanks in advance for any help or ideas.

If you are making AJAX calls before you get the "deviceready" event it is probably delaying the onPageFinished event from the native side of Android. Try putting the AJAX calls in your deviceready event handler.

We solved this issue by putting a 1 second timeout on the function call that launches the asynchronous requests. I'm not going to accept this as an answer, as it's more of a work-around than a solution. From my time spent working on this problem, all I can say is that it appears that Cordova waits for javascript to idle before removing the splash screen. As the asynchronous call was the last call made before the javascript would naturally idle, putting a 1 second timeout on it seemed to work. The odd thing is that, seeing as it's an asynchronous call, javascript should have idled directly after the call anyway. Perhaps Cordova also waits for the network to be quiet. This is just speculation, but hopefully it gives future readers some ideas on how to fix their problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM