0

我在工作灯上实现了一个应用程序,我需要从服务器下载文件,它在 Iphone5 上运行良好意味着文件可以顺利下载而不会卡住应用程序流程。但是当我在三星 Galaxy s2(V 4.1)上运行应用程序时并开始使用 for 循环下载文件,我的应用程序卡住了,直到下载完成。但是,当我只有一个文件要下载但计数高于 3 或 4 个时,它的工作正常,应用程序卡住了。

如果(networkInfo.networkConnectionType=='WIFI'){

                                $(brandClassDis).addClass('ui-disabled'); // Disabling the Brand.
                                $(".lms_loadernew").css("display", "block");
                                var syncProgBar = "#syncProgressBar"+result[0].json.BrandID;
                                var syncProgLabel = "#syncLoadingLabel"+result[0].json.BrandID;
                                $(syncProgBar).progressbar({
                                    value: 0,
                                }).show();
                                $(syncProgLabel).text(parseInt(0, 10)+"%").show();
                                localStorage.setItem("download"+result[0].json.BrandID,0);
                                localStorage.setItem("downloadSucc"+result[0].json.BrandID,0);
                                for(var i=0; i<result.length; i++){
                                    var obj = {VideoID:result[i].json.VideoID,BrandID:result[i].json.BrandID,CourseID:result[i].json.CourseID,LoadingStatus:"0"};
                                    VideosList.add(obj,{push:false});
                                    result[i].json.IsDownload = 2;
                                    Videos.replace(result);

                                            **downloadFolder(result[i],result.length)**

                                }   
                            }

函数下载文件夹(结果,numVideoBrand){

try{
    var loaderPer = 0;
    var courseId ="#sync_"+result.json.CourseID.replace(/ /g,'');
    var courseLabelId ="#loadingLabel"+result.json.CourseID.replace(/ /g,'');
    var syncProgBar = "#syncProgressBar"+result.json.BrandID.replace(/ /g,'');
    var syncProgLabel = "#syncLoadingLabel"+result.json.BrandID.replace(/ /g,'');
    var serverLoc = encodeURI(result.json.DownloadName);
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
        fileSystem.root.getDirectory("LMS_APP", {create: true, exclusive: false}, function(directory){
            var localPath = directory.fullPath+"/"+"Videos"+"/"+zipFileName;
            var ft = new FileTransfer();
            ft.download(serverLoc,localPath, function(entry) {
                entry.file(function(file) {
                    WL.Logger.debug("File size: " + file.size);
                    if(file.size<=854){
                        downloadFail("",result,numVideoBrand);
                        entry.remove(successRemove, failRemove);
                    }else{
                        if(localStorage.getItem("download"+result.json.BrandID) == null || localStorage.getItem("download"+result.json.BrandID) =="" || localStorage.getItem("download"+result.json.BrandID) == undefined){
                            localStorage.setItem("download"+result.json.BrandID,1);
                        }else{
                            localStorage.setItem("download"+result.json.BrandID,(localStorage.getItem("download"+result.json.BrandID)-(-1)));
                        }

                        localStorage.setItem("downloadSucc"+result.json.BrandID,(localStorage.getItem("downloadSucc"+result.json.BrandID)-(-1)));

                        WL.Logger.debug("Folder is:---->"+directory.fullPath+"/"+zipFileName);
                        WL.Logger.debug("download"+localStorage.getItem("download"+result.json.BrandID)+"..."+numVideoBrand+"........"+ localStorage.getItem("downloadSucc"+result.json.BrandID));
                        var loadedVideoPer = (( localStorage.getItem("download"+result.json.BrandID)/numVideoBrand)* 100);
                        $(syncProgBar).progressbar({
                            value: loadedVideoPer,
                        });
                        $(syncProgLabel).text(parseInt(loadedVideoPer, 10)+"%");
                        $(courseId).hide();
                        $(courseLabelId).hide();
                    }
                }, function(error){downloadFail(error,result,numVideoBrand);});

            }, function(error) {

            });
            $(courseId).progressbar({
                value: loaderPer,
            }).show();

            $(courseLabelId).text(parseInt(loaderPer, 10)+"%").show();

            ft.onprogress = function(progressEvent) {

                if (progressEvent.lengthComputable) {
                    loaderPer = ((progressEvent.loaded / progressEvent.total)*100);
                    $(courseId).progressbar({
                        value: loaderPer,
                    });
                    $(courseLabelId).text(parseInt(loaderPer, 10)+"%");
                    //courseLabelId.text(parseInt(loaderPer, 10) + "%" );
                    loadingStatus(result);
                } 
            };  

        },function(error){
            downloadFail(error,result,numVideoBrand);
        });

    }, function(error){
        downloadFail(error,result,numVideoBrand);
    });
}catch(e){

    WL.Logger.debug("exp in downloadFile: "+e);
    //alert("exp "+videoLoader);
}

}

4

1 回答 1

0

根据评论,解决方案是:

下载队列中的文件,因为一次下载所有文件会导致应用程序卡住...

于 2015-01-02T14:10:43.637 回答