简体   繁体   English

回到前台时应用程序冻结(Cordova 3 + jquery mobile)

[英]Application freeze when bring back to foreground (Cordova 3 + jquery mobile)

We are developing a mobile application using latest AC (3.1.0) + jquery mobile.我们正在使用最新的 AC (3.1.0) + jquery mobile 开发移动应用程序。 The application is live on google play store ( https://play.google.com/store/apps/details?id=com.mventix.sellPro&hl=bg ) but we are having strange issue.该应用程序在 google Play 商店( https://play.google.com/store/apps/details?id=com.mventix.sellPro&hl=bg )上上线,但我们遇到了奇怪的问题。 When the app is started there is no problem of opening different views and do some stuff.当应用程序启动时,打开不同的视图并做一些事情是没有问题的。 But when the application goes in background for some period of time (as far as it happens between 10minutes and 2-3 hours) and after resuming the application the user interface is frozen and nothing is responding also no error is printed in logcat.但是当应用程序在后台运行一段时间(就它发生在 10 分钟到 2-3 小时之间)并且恢复应用程序后,用户界面被冻结并且没有任何响应,logcat 中也没有打印错误。 We have to kill the application and restart it to make it work.我们必须杀死应用程序并重新启动它才能使其工作。 Also we are using WEBSQL and LocalStorage also we are storing some files in the app/cache/ because the app needs to run without internet.此外,我们正在使用 WEBSQL 和 LocalStorage,我们还在 app/cache/ 中存储了一些文件,因为该应用程序需要在没有互联网的情况下运行。 And we are using a lot of the plugins that are in cordova.我们使用了许多cordova 中的插件。 I found similar bugs in apache cordova bugtracker but they are for older cordova versions.我在 apache cordova bugtracker 中发现了类似的错误,但它们适用于较旧的cordova 版本。

similar bug类似的错误

In both places the problem looks similar but as far as i understand they are fixed in the latest cordova version.在这两个地方,问题看起来很相似,但据我所知,它们已在最新的cordova 版本中得到修复。

This problem is represented over (android 4.0.3, 4.1.2, 4.2.2) over those devices are LG nitro, HP slate 7 Samsung GT2 7inch samsung sIII and s IV.这个问题在 (android 4.0.3, 4.1.2, 4.2.2) 上表现出来,这些设备是 LG nitro、HP slate 7 Samsung GT2 7inch samsung sIII 和 s IV。

In that order i read and search all around the phonegap forum and stackoverflow but nothing that i've tried fixed my problem.按照这个顺序,我在 phonegap 论坛和 stackoverflow 周围阅读和搜索,但我尝试过的任何内容都无法解决我的问题。 As far now we tried:到目前为止,我们尝试过:

@Override
public void onDestroy() {
    // TODO Auto-generated method stub
    super.loadUrl("about:blank");
    super.onDestroy();
}

Also we tried this fix to make bigger timeout @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);我们也尝试了这个修复来增加超时时间 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

    super.init();
    super.setIntegerProperty("loadUrlTimeoutValue", 60000);
    super.setBooleanProperty("keepRunning", false);
    super.loadUrl(Config.getStartUrl());

Our config.xml looks like this:我们的 config.xml 看起来像这样:

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.helloCordova" version="2.0.0" xmlns="http://www.w3.org/ns/widgets">
    <name>SellPro</name>
    <description>
        SellPro
    </description>
    <author email="support@vertinity.com" href="http://www.vertinity.com">
        Vertinity LTD Team
    </author>
    <content src="index.html" />
    <feature name="App">
        <param name="android-package" value="org.apache.cordova.App" />
    </feature>
    <access origin="*" />
    <preference name="useBrowserHistory" value="false" />
    <preference name="exit-on-suspend" value="true" />
    <preference name="fullscreen" value="false" />
    <preference name="webviewbounce" value="true" />
    <preference name="splashscreen" value="splash" />
    <preference name="splashScreenDelay" value="10000" />
    <feature name="File">
        <param name="android-package" value="org.apache.cordova.core.FileUtils" />
    </feature>
    <feature name="FileTransfer">
        <param name="android-package" value="org.apache.cordova.core.FileTransfer" />
    </feature>
    <feature name="ExtractZipFilePlugin">
        <param name="android-package" value="org.apache.cordova.core.ExtractZipFilePlugin" />
    </feature>
    <feature name="PdfPanel">
        <param name="android-package" value="com.vertinity.pdfPanel.PdfPanel" />
    </feature>
    <feature name="SocialShare">
        <param name="android-package" value="com.vertinity.socialShare.SocialShare" />
    </feature>
    <feature name="Media">
        <param name="android-package" value="org.apache.cordova.core.AudioHandler" />
    </feature>
    <feature name="MXPlayer">
        <param name="android-package" value="com.vertinity.mxPlayer.MXPlayer" />
    </feature>
    <feature name="org.apache.cordova.core.ParsePlugin">
        <param name="android-package" value="org.apache.cordova.core.ParsePlugin" />
    </feature>
    <feature name="WebIntent">
        <param name="android-package" value="android.WebIntent" />
    </feature>
    <feature name="NetworkStatus">
        <param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
    </feature>
    <feature name="SplashScreen">
        <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
    </feature>
</widget>

Our andoidManifest looks like this:我们的 andoidManifest 看起来像这样:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:clearTaskOnLaunch="true" 
          android:hardwareAccelerated="true" 
          android:versionCode="4" 
          android:versionName="1.0.12"  
          package="com.mventix.sellPro" 
          xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" 
                      android:largeScreens="true" 
                      android:normalScreens="true" 
                      android:resizeable="true" 
                      android:smallScreens="true" 
                      android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-feature android:name="android.hardware.telephony" android:required="false" />
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="16" />
    <application android:debuggable="true"
                 android:hardwareAccelerated="true"
                 android:largeHeap="true" 
                 android:clearTaskOnLaunch="true" 
                 android:icon="@drawable/icon" 
                 android:label="@string/app_name" 
                 android:name=".sellProApplication" >
        <activity android:screenOrientation="portrait" 
                  android:windowSoftInputMode="adjustResize" 
                  android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" 
                  android:label="@string/app_name" 
                  android:name="sellPro" 
                  android:theme="@android:style/Theme.Black.NoTitleBar" 
                  android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.facebook.LoginActivity"
            android:label="@string/app_name" >
        </activity>
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
        <service android:name="com.parse.PushService" />
        <receiver android:name="com.parse.ParseBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

I hope someone can help me or just explain me what exactly is happening so I can start researching in the right direction.我希望有人可以帮助我,或者只是向我解释到底发生了什么,以便我可以开始朝着正确的方向进行研究。 If someone needs additional info I will provide all the data needed.如果有人需要其他信息,我将提供所需的所有数据。

Kind Regards Tsvetan亲切的问候茨维坦

I can remember that once i've had similar issues, when suspending my app.我记得有一次我遇到了类似的问题,暂停我的应用程序时。 Somehow (i do not know why) window.device has'nt been (re)initialized properly when returning from suspendmode.从挂起模式返回时,不知何故(我不知道为什么) window.device没有被(重新)正确初始化。

So i've decided to give phonegap a 1000ms more time on getting it's window.device所以我决定给 phonegap 多 1000 毫秒的时间来获取它的window.device

Here is a smapleCode to get an idea of what i mean:这是一个 smapleCode 来了解我的意思:

Everything start with init();一切都从init()开始

<body onload="init()">
</body>

And a ScriptBlock in the <head> section:以及<head>部分中的 ScriptBlock:

        <script type="text/javascript">

        function init(){
            console.log("init() called");
            var promiseDeviceReady = onDeviceReady();
            promiseDeviceReady.done(doPhoneGapStuff); //start PhoneGap action
        }   

        function onDeviceReady() {  
            var deferred = $.Deferred();
            var timeOut = 0;


            //set a 1sec timeOut when App was send to suspendMode. SomeTimes PhoneGap needs it's time...
            if (!window.device){ 
                console.log("PhoneGap seems not to be ready yet!!!")
                timeOut = 1000; 
            }

            setTimeout(function() {
                deferred.resolve();
            }, timeOut);

            return deferred.promise();
        }

    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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