1

The issue:

I am facing this issue since I have updated from PhoneGap 3.0.0 to 3.1.0.

11-08 15:30:54.997: E/CordovaWebView(32728): CordovaWebView: TIMEOUT ERROR!

The Code

I have the following code in my main Java:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Splash screen
    super.setIntegerProperty("splashscreen", R.drawable.splash);

    super.loadUrl(Config.getStartUrl(), 10000);

    mContext = getApplicationContext();
    appView.addJavascriptInterface(new JSInterface(), "JSPlugin");
}

Relevant part of Config.xml:

<preference name="show-splash-screen-spinner" value="false" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="splashscreen" value="splash" />
<preference name="splashScreenDelay" value="5000" />
<feature name="SplashScreen">
    <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
</feature>

Index.html (onDeviceReady runs fine, but hide() doesn't make any difference):

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    navigator.splashscreen.hide();
}

What happens is the following:

The app loads and the splashscreen displays but it doesn't hide. So after a while I get the CordovaWebView: TIMEOUT ERROR! and the app crashes.
On the screen I get an error:

Application Error
The connection to the server was unsuccessful.
(javascript:JSPlugin.myFunction('...');)

It crashes on both Android 4.2 and Android 4.3 but it runs fine on iOS 6 and iOS 7.

What I have tried is:

  • Cordova update npm install -g cordova
  • Platform update: cordova platform update android
  • Removing and adding Splashscreen plugin again cordova plugin remove org.apache.cordova.splashscreen and cordova plugin add org.apache.cordova.splashscreen. Also tried the same with phonegap phonegap local plugin...
  • After plugin re-install: cordova build android

  • I tried to remove this line super.setIntegerProperty("splashscreen", R.drawable.splash); from the main .java because i have the Config.xml preference <preference name="splashscreen" value="splash" />. Still crashes.

  • Removing Splashscreen: if I completely remove the splashscreen preference from Config.xml the app loads but obviously without the splashscreen.

  • I have tried this as well: phonegap 3.1 - Unable to hide splash screen on device ready

4

1 回答 1

1

我刚刚发现为什么会发生这种情况。这很奇怪,因为最后似乎解决方案与SplashScreen. 仍然只有在启用时才splashscreen存在。

我有一个Init()启动的功能onDeviceReady()。这从init()调用一个JAVA函数JavaScript

我从 Javascript 调用 JAVA 的方式是通过@JavascriptInterfacewindow.JSPlugin.myFunction();在 JavaScript 代码中。在我升级到PhoneGap 3.1之前它一直有效,但在它崩溃之后。

然而,这在早期的 Cordova / PhoneGap 版本中有记录,@JavascriptInterface并且window.JSPlugin.myFunction()方法仍然有效。

最奇怪的是为什么只有 SplashScreen 插件会破坏这个?

解决方案

是使用PhoneGap方法(无论如何我都在使用它):

cordova.exec(function(){},function(){},'com.myApp.JSPlugin','myFunction()',[]);
于 2013-11-11T15:56:59.143 回答