开发者

JQuery.Hive on Android (Worker Threads)

i am currently writing an app that shows the menu plan of the cafeteria at our university. To make it platform-independent i use Phonegap; The XML-Parsing ist done with the help of JQuery, the layout is generated with JQuery Mobile.

Parsing the XML-File for the menus takes around 1-2 seconds on my motorola defy. If you for example change the location to another cafeteria by clicking the radio button the GUI freezes for this second. I found the concept of Worker Threads in JavaScript and decided to delegate the parsing of the XML-data to a Worker Thread. Unfortunately i had to find out that JQuery does not work within Worker Threads :开发者_如何转开发-( Then i found the Plugin JQuery.hive which seemed to solve my problems. I now create the Thread within the hive-environment, send a message, process it inside the Worker Thread and receive an answer. Unfortunately this works only in Firefox and not in my Android/Phonegap-Application.

This is where i generate the Worker:

$(function() {

$("#mydiv").append("Start |");

$.Hive.create({
    worker : 'Worker_Parser.js',
    receive : function(data) {

    $("#mydiv").append('RECEIVED MESSAGE: ' + data.message + ' | ');
            }           
        });
$("#mydiv").append("Worker generated | ");
    });

$.Hive.get(0).send("test");

$("#mydiv").append("End ");

This is the worker thread:

importScripts('jquery.hive.pollen.js');

$(function (data) {
       $.send("test");
     });

Firefox shows

Start | Worker generated | End | RECEIVED MESSAGE: test | 

The Android Broswer cancels the script when attemping to start a Thread and shows only:

Start |

Is JQuery.hive supposed to run under Android at all? Is there a better way to solve my problem of parsing XML without freezing the GUI?

Thanks in advance,

Tom


Looking here, you'll see that Web Workers are not supported by the current Android browser, nor by iOS.

Could you break the data down further in the XML file, and send it in smaller chunks based on user interaction, instead of sending the whole menu at once? Perhaps shrink the menu request only to the current day and fire off AJAX requests for other days?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜