Phonegap cordova 2.7.0 error when pausing app

2019-02-16 13:45发布

问题:

I've created a clean cordova 2.7.0 project by using the phonegap tool "create" (create project_folder package_name project_name) and I've deployed the app to my Nexus 4 (androind 4.2.2). No code has been written.

The app has been executed with no errors because it has shown the phonegap logo and "apache cordova device is ready". The problem is that when I tap the standard android right button(which shows recent running apps) I see in the eclipse LogCat that an error ocurrs:

05-07 18:29:54.957: D/webviewglue(24649): nativeDestroy view: 0x731f4738
05-07 18:30:10.163: D/DroidGap(24649): Paused the application!
05-07 18:30:10.163: D/CordovaWebView(24649): Handle the pause
05-07 18:30:10.453: W/IInputConnectionWrapper(24649): showStatusIcon on inactive InputConnection
05-07 18:30:10.743: D/DroidGap(24649): onDestroy()
05-07 18:30:10.743: D/CordovaWebView(24649): >>> loadUrl(javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};)
05-07 18:30:10.743: D/PluginManager(24649): init()
05-07 18:30:10.753: D/CordovaWebView(24649): >>> loadUrlNow()
05-07 18:30:30.765: E/CordovaWebView(24649): CordovaWebView: TIMEOUT ERROR!
05-07 18:30:30.765: D/Cordova(24649): CordovaWebViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};
05-07 18:30:30.765: D/DroidGap(24649): onMessage(onReceivedError,{"errorCode":-6,"url":"javascript:try{cordova.require('cordova\/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};","description":"The connection to the server was unsuccessful."})

After this error I tap the app from the list and a popup titled "Application Error" appears containing exactly this message:

"The connection to the server was unsuccessful. (javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};)"

This behavior happens always (sometimes it requires to pause the app by using the recent apps list button twice).

Any ideas?

Thank you in advance.

UPDATE: As suggested by Romain Braun by using 2.4.0 the error does not occur.

回答1:

This bug appeared after the release of Cordova 2.5

Yet no one has found a solution.

I'd recommend reporting the bug to the phonegap team, and downgrading your Cordova version to 2.4 if it is possible.



回答2:

Try increasing the load timeout value in the onCreate method of your Java class that extends DroidGap:

super.setIntegerProperty("loadUrlTimeoutValue", 60000); 


回答3:

I had the same problem and it was also fixed with when I used 2.4, but I decided to post it as an issue on their issue tracker: https://issues.apache.org/jira/browse/CB-3749

Apparently for me it happened because I had removed a few lines in my manifest, because I was targeting android-10, but I should have just targeted android-17 since phonegap itself works for android-10, without me having to target it.



回答4:

I was having this annoying issue until I realized I was using the wrong Cordova.js file. Changed it and the problem is gone. Im using phonegap 2.7.



回答5:

I think this error is very broad and symptomatic of a number of issues.I have got it when I was overriding the onPageFinished and onPageStarted methods on my webview client and forgot to call super.onPageFinished(view, url) for example.

Note that timeouts are "cleared" on these methods:

https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/CordovaWebViewClient.java#L299



回答6:

I had the same error with Cordova 2.5 and reverted back to 2.4. I've recently tried 2.9 and I'm no longer getting the error.



回答7:

Please dont use webview.handlePause(false) in Activity's onPause() method, but only use webview.handleDestroy() in Activity's onDestroy() method instead.

It happens when user re-open activity , and we fixed it in that way in our app.

Cordova-2.5.jar