cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Almilli (JIRA)" <>
Subject [jira] [Created] (CB-7197) Cordova doesn't always initialize when webview timers start in the paused state
Date Fri, 25 Jul 2014 15:50:38 GMT
David Almilli created CB-7197:

             Summary: Cordova doesn't always initialize when webview timers start in the paused
                 Key: CB-7197
             Project: Apache Cordova
          Issue Type: Bug
          Components: Android
    Affects Versions: 3.5.0
         Environment: Android 4.4.2
            Reporter: David Almilli
            Priority: Blocker

When Cordova pauses the timers before the Activity is destroyed, when you start the Activity
back up, it detects it's in the startup phase and doesn't resume the timers if they are starting
in the paused state.

If you look at the javadoc for WebView.pauseTimers() it says that it's a global setting and
doesn't just affect that instance of the WebView.

There are probably several ways to reproduce this which may seem inconsistent because it depends
on what the android task manager does and whether it destroys the activities, but keeps the
process running or not. I wasn't able to make a simple example though. The way I was reproducing
it was by using the camera plugin to take a picture and then hit back repeatedly until it
goes to the home screen.  Then I would go back to the launcher icon to start the app again.
 It never receives the deviceready event and gets stuck just before it loads the plugins in
the cordova.js because it's wrapped in a setTimeout().

I even had this snipped at the top of the body that (when starting in a broken state) would
print "Testing setTimeout", but would *not print* "setTimeout 0 works"
		<script type="text/javascript">
			console.log("Testing setTimeout");
			setTimeout(function() {
				console.log("setTimeout 0 works");
			}, 0);

The fix I came up with was at the end of the CordovaActivity.init(...) method add this line:
    public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient
webChromeClient) {

And to be sure that the CordovaWebView doesn't break other WebViews that might be used by
a developer, it should resume the timers when it is destroyed so at the end of the CordovaWebView.handleDestory()
method add this line:
    public void handleDestroy() {

This message was sent by Atlassian JIRA

View raw message