Return-Path: X-Original-To: apmail-cordova-issues-archive@minotaur.apache.org Delivered-To: apmail-cordova-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BC468100A5 for ; Thu, 19 Feb 2015 08:50:18 +0000 (UTC) Received: (qmail 71741 invoked by uid 500); 19 Feb 2015 08:50:12 -0000 Delivered-To: apmail-cordova-issues-archive@cordova.apache.org Received: (qmail 71713 invoked by uid 500); 19 Feb 2015 08:50:12 -0000 Mailing-List: contact issues-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@cordova.apache.org Received: (qmail 71367 invoked by uid 99); 19 Feb 2015 08:50:12 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Feb 2015 08:50:12 +0000 Date: Thu, 19 Feb 2015 08:50:12 +0000 (UTC) From: "Or Arnon (JIRA)" To: issues@cordova.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (CB-7197) Cordova doesn't always initialize when webview timers start in the paused state MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CB-7197?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14327129#comment-14327129 ] Or Arnon edited comment on CB-7197 at 2/19/15 8:49 AM: ------------------------------------------------------- hi everyone, this issue can easily reproduced if there is more than one webview running in your app, for example: if you have an ad network SDK installed in your app. apparently, most ad-tech SDKs use webviews to show their ads. when an ad is shown before the Cordova activity (and webview) is shown, then this can cause the Cordova webview to hang and/or not load its content. after decompiling the ad network SDK jar file, i noticed that they run the following code: onPause { if (this.webView != null) { this.webView.clearHistory(); this.webView.clearCache(true); this.webView.clearAnimation(); this.webView.loadUrl("about:blank"); this.webView.freeMemory(); this.webView.pauseTimers(); <---------------------------- this.webView.clearView(); this.b.destroy(); } } now when i start my Cordova activity, the activity's onResume is called, but the webview resumeTimers is NOT called, because it was the first time that the Cordova activity's onResume method was called. from the CordovaActivity code: private int activityState = 0; // 0=starting, 1=running (after 1st resume), 2=shutting down protected void onResume() { super.onResume(); LOG.d(TAG, "Resuming the App"); if (this.activityState == ACTIVITY_STARTING) { this.activityState = ACTIVITY_RUNNING; return; <---------------------------- } if (this.appView == null) { return; } // Force window to have focus, so application always // receive user input. Workaround for some devices (Samsung Galaxy Note 3 at least) this.getWindow().getDecorView().requestFocus(); this.appView.handleResume(this.keepRunning, this.activityResultKeepRunning); .... } was (Author: oratthumzap): hi everyone, this issue can easily reproduced if there is more than one webview running in your app, for example: if you have an ad network SDK installed in your app. apparently, most ad-tech SDKs use webviews to show their ads. when an ad is shown before the Cordova activity (and webview) is shown, then this can cause the Cordova webview to hang and/or not load its content. after decompiling the ad network SDK jar file, i noticed that they run the following code: onPause { if (this.webView != null) { this.webView.clearHistory(); this.webView.clearCache(true); this.webView.clearAnimation(); this.webView.loadUrl("about:blank"); this.webView.freeMemory(); this.webView.pauseTimers(); <---------------------------- this.webView.clearView(); this.b.destroy(); } } now when i start my Cordova activity, the activity's onResume is called, but the webview resumeTimers is NOT called, because it was the first time that the Cordova activity's onResume method was called. from the CordovaActivity code: private int activityState = 0; // 0=starting, 1=running (after 1st resume), 2=shutting down protected void onResume() { super.onResume(); LOG.d(TAG, "Resuming the App"); if (this.activityState == ACTIVITY_STARTING) { this.activityState = ACTIVITY_RUNNING; return; <---------------------------- } if (this.appView == null) { return; } // Force window to have focus, so application always // receive user input. Workaround for some devices (Samsung Galaxy Note 3 at least) this.getWindow().getDecorView().requestFocus(); this.appView.handleResume(this.keepRunning, this.activityResultKeepRunning); .... } > Cordova doesn't always initialize when webview timers start in the paused state > ------------------------------------------------------------------------------- > > Key: CB-7197 > URL: https://issues.apache.org/jira/browse/CB-7197 > Project: Apache Cordova > Issue Type: Bug > Components: Android > Affects Versions: 3.5.0 > Environment: Android 4.4.2 > Reporter: David Almilli > > 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. > http://developer.android.com/reference/android/webkit/WebView.html#pauseTimers() > 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" > {noformat} > > {noformat} > The fix I came up with was at the end of the CordovaActivity.init(...) method add this line: > {noformat} > public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) { > ... > this.appView.resumeTimers(); > } > {noformat} > 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: > {noformat} > public void handleDestroy() { > ... > this.resumeTimers(); > } > {noformat} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org For additional commands, e-mail: issues-help@cordova.apache.org