首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >回到前台时应用程序冻结(Cordova 3+ jquery mobile)

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

Stack Overflow用户
提问于 2013-10-22 13:50:29
回答 1查看 3.2K关注 0票数 4

我们正在使用最新的AC (3.1.0) + jquery开发一个移动应用程序。这个应用程序是在google商店(https://play.google.com/store/apps/details?id=com.mventix.sellPro&hl=bg)上运行的,但是我们遇到了奇怪的问题。当应用程序启动时,打开不同的视图并做一些事情是没有问题的。但是,当应用程序在后台运行一段时间(在10分钟到2-3小时之间),在恢复应用程序之后,用户界面被冻结,没有响应,也没有在logcat中打印错误。我们必须关闭应用程序并重新启动它以使其正常工作。另外,我们使用WEBSQL和LocalStorage,我们还在app/cache/中存储一些文件,因为应用程序需要在没有互联网的情况下运行。我们正在使用科多瓦的许多插件。我在apache中发现了类似的bug,但它们适用于较老的cordova版本。

相似虫

在这两个地方,问题看起来很相似,但据我所知,它们在最新的cordova版本中得到了解决。

这个问题表现在(Android4.0.3,4.1.2,4.2.2)上,这些设备是LG硝基,惠普平板7三星GT2 7英寸三星sIII和s IV。

按照这个顺序,我在phonegap论坛和堆栈溢出论坛周围阅读和搜索,但没有任何尝试解决了我的问题。到目前为止,我们尝试了:

代码语言:javascript
复制
@Override
public void onDestroy() {
    // TODO Auto-generated method stub
    super.loadUrl("about:blank");
    super.onDestroy();
}

此外,我们尝试了这个补丁,以使更大的超时值@覆盖公共无效onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

代码语言:javascript
复制
    super.init();
    super.setIntegerProperty("loadUrlTimeoutValue", 60000);
    super.setBooleanProperty("keepRunning", false);
    super.loadUrl(Config.getStartUrl());

我们的config.xml看起来如下:

代码语言:javascript
复制
<?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>

我们的andoidManifest看起来如下:

代码语言:javascript
复制
<?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>

我希望有人能帮助我,或者解释一下到底发生了什么,这样我才能开始朝着正确的方向进行研究。如果有人需要更多的信息,我将提供所有需要的数据。

亲切问候茨维坦

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-07 21:03:30

我记得曾经有过类似的问题,当我暂停我的应用程序。不知何故(我不知道为什么),window.device在从挂起模式返回时没有被正确初始化。

所以我决定给phonegap多1000毫秒的时间来获得它的window.device

这里有一个smapleCode来了解我的意思:

一切都以init();开头

代码语言:javascript
复制
<body onload="init()">
</body>

以及<head>部分中的ScriptBlock:

代码语言:javascript
复制
        <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>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19519824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档