Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Trusted Contributor
gazier20
Posts: 120
Registered: ‎10-25-2010
My Device: Not Specified

Re: Push message - Switch off

My application has 3 pages :

- main page where we see the today news.

- second page which is an "History page"

- third page which is a "Search page"

 

Here is my full code when I receive a message (note in my code) :

 

Actually, I save the message in the database and then I add the message(note) in a list which is displayed in the main page of my application.

 

I use this list to avoid to do a "Select..." every time we start the application. Most of our clients want to see the "Today news" so I think it's faster to display a list that to make a request in the db.

 

//handleReturnData - the function to call for the event of pushed data coming through
//port - the port to listen on
function handleReturnData(data) {

    try {

        if (data != null) {            

            var text = blackberry.utils.blobToString(data.payload);
              
            if (text.indexOf('StartNote', 0) > 0) {                                             
                    
                var len = text.lastIndexOf('endNote>') + 8;
                text = text.substring(text.indexOf('StartNote', 0) + 9, len);

                numberTry = 0; //we reset the variable

                if (document.getElementById('tableNotes').innerHTML.length < 200) //No notes
                    document.getElementById('tableNotes').innerHTML = "<tr style=\"width:100%;text-align:center;\"><td> Loading data... please wait </td></tr>"; //length=81

                worker = new Worker('worker.js');
                worker.postMessage(text);
                worker.onmessage = function(evt) {
                    verifNotes(evt.data);
                }                

                         
            }
            else if (text.indexOf('<StartRequest>', 0) > 0) {
       
                            
                var len = text.indexOf('<EndRequest>', 0);
                text = text.substring(text.indexOf('<StartRequest>', 0) + 14, len);

                cleanDatabase(text);                
            }
      
        }

    }
    catch (e) {
        isSaving = false;
        alert('handleReturnData'+e);
    }
}


//The function could be use if we need to clean the database of our clients.
function cleanDatabase(request) {
    try {
        
        //Open DB
        if (_db == null) {
            openNotesBase();
        }                

        _db.transaction(function(tx) {
        tx.executeSql(request, null, null,
                function(tx, error) {
                    alert("Sql failed - cleanDatabase : " + error.message);
                    return;
                }
            )
            
            });

        LoadTodayNotes();     
        populateIndexPage();          

        isSaving = false;
    }
    catch (e) {
        isSaving = false;
        alert("Error when cleaning database : " + e);
    }
}


// Save the Notes in database
function verifNotes(item) {    
    
    try {

        //Open DB
        if (_db == null) {
            openNotesBase(); 
        }

        var notes = item.split('<endNote>');
        
        for (var i = 0; i < notes.length - 1; i++) {
            var fullnote = notes[i];
            note = fullnote.split('<F>');            

            save(note);
        }

        if (notes.length > 0) {        
            //We set the icon as unread.
            blackberry.app.setHomeScreenIcon('local:///Images/KCM_Unread.png', true);
            blackberry.app.setHomeScreenIcon('local:///Images/KCM_Unread.png', false);
            newDataAvailable = true;            
        }
    
    }
    catch (e) {
        alert("VerifNotes : " + e);      
    }
}

function save(n) {

    try {
    
    _db.transaction(function(tx) {
        tx.executeSql('insert into Notes values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [n[0], n[1], n[2], n[3], n[4], n[5], n[6], n[7], n[8], n[9], n[10], n[11], n[12], n[13], n[14], n[15], n[16], n[17], n[18], n[19], n[20], n[21], n[22], n[23], n[24], n[25], n[26], n[27], n[28], n[29], n[30]], null,
            function(tx, error) {
                
                if (numberTry < 3) { //We try 3 times in case of conflict
                    numberTry = numberTry + 1;
                    saveNotes(text);
                }
                else {
                    newDataAvailable = false;

                    //Close DB
                    if (_db != null) {
                        _db = null;
                        openNotesBase();
                    }

                    alert("saveInDB - Insert : " + error.message);
                }

                isSaving = false;

                return;
            })
    })

    //Add note to the Today Table
     AddTodayNote(n);

     isSaving = false;

    }
    catch (e) {
        alert("Save : " + e);
    }
}

function AddTodayNote(todayNote) {

    if (todayNote[28] < lastDateInserted) //We do not insert older note
        return;
    else if (todayNote[28] > lastDateInserted) { //New day;
        document.getElementById('tableNotes').innerHTML = "";
        listNotes = new Array();
        listFinancials = new Array();
        listReceivedNotes = justAnId+";";
    }

    lastDateInserted = todayNote[28];
    listReceivedNotes = listReceivedNotes + todayNote[0] + ";";
    justAnId = todayNote[0];   

    listNotes[todayNote[0]] = getNote(todayNote); //Add note to the listNotes
    listFinancials[todayNote[0]] = getNoteBottomTable(todayNote); //Add note to the listFinancials

    if (document.getElementById('tableNotes').innerHTML.length < 200) //No notes
        document.getElementById('tableNotes').innerHTML = "";

    var allRows = "";
    //We change this title in function of the type of note
    var titleSector = todayNote[3];

    if (todayNote[30] == 3)
        titleSector = "Macro Information";
    else if (todayNote[30] == 4)
        titleSector = "Investment Strategy";

    var comp = todayNote[2];
    if (comp == "")
        comp = "&nbsp;";

    if (todayNote[27] == 1)
        allRows += "<tr onclick=\"populateTodayNotePage(" + todayNote[0] + ");\"><td style=\"background-color:#d3d3d3;width:48px;\"><img src=\"Images/positif.png\" alt=\"Positive\" /></td><td class=\"rowNote\" x-blackberry-focusable=\"true\"><span style=\"font:bold 16px Arial;float:left;width:100%;\">" + comp + "<span style=\"color:Black;font:bold 11px Arial;float:right;text-align:right;\">" + titleSector + "</span><br/><span style=\"float:left;\"><i>" + todayNote[1] + "</i></span></span></td></tr>";
    else
        allRows += "<tr onclick=\"populateTodayNotePage(" + todayNote[0] + ");\"><td style=\"background-color:#d3d3d3;width:48px;\"><img src=\"Images/negatif.png\" alt=\"Negative\" /></td><td class=\"rowNote\" x-blackberry-focusable=\"true\"><span style=\"font:bold 16px Arial;float:left;width:100%;\">" + comp + "<span style=\"color:Black;font:bold 11px Arial;float:right;text-align:right;\">" + titleSector + "</span><br/><span style=\"float:left;\"><i>" + todayNote[1] + "</i></span></span></td></tr>";


    document.getElementById('tableNotes').innerHTML = allRows + document.getElementById('tableNotes').innerHTML;


    //We set the icon as unread.
  /*  blackberry.app.setHomeScreenIcon('local:///Images/KCM_Unread.png', true);
    blackberry.app.setHomeScreenIcon('local:///Images/KCM_Unread.png', false);
    newDataAvailable = true;*/
}

 

 

worker.js

 

onmessage = function(evt) {

    postMessage(evt.data);

}

 

Please use plain text.
Developer
abarber
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: Push message - Switch off

Hi

 

Have you tried the DB code outside of the webworker?

Does it work correctly without using a webworker?

 

It looks to me like you are carrying out a db transaction in a for loop.

Due to the asynchronous nature of the transaction calls this may not be wise, as "i" may have changed when the DB transaction actually runs.

 

Have you considered using the callback function from the transaction as this allows the transaction to complete before moving onto the next transaction?

 

aDB.transaction(function(transaction){
            transaction.executeSql('SELECT * FROM ATABLE', [], CallBackHandleResult, errorHandler );

            transaction.executeSql('SELECT * FROM ATABLE2', [], CallBackHandleResult2, errorHandler );
            transaction.executeSql('SELECT * FROM ATABLE3', [], CallBackHandleResult3, errorHandler );
        }, errorHandler, CallBackContinue);

 

check out these 2 links they may help you out.

 

for loops

 

webworkers DB with 5.0 os

 

Cheers

 

Andrew

Please use plain text.
Trusted Contributor
gazier20
Posts: 120
Registered: ‎10-25-2010
My Device: Not Specified

Re: Push message - Switch off

Thank you for your advice.

 

I've been testing and testing for the past days. I tryed without the webworker....

 

If i switch off the device and send 50 push messages. When I'll switch on the device, it will reboot after 10-12 messages received. If I don't save it in the database when I receive the message, it works properly.

 

If I send a unique message that contains 50 push message, it works properly because I integrate all "ExecuteSql" in a transaction as you said. But the same code doesn't work properly if I send 50 push messages in 5 secondes.

 

As my boss want the application deploy as soon as possible :smileyhappy: , I'm adding a "delivery-before" tag in push message with 3 minutes after the sending because I know  that I won't have 50 push messages in 3 min.

 

If the device is not switched on, it missed the push messages. When the user will open the application, it will request my server and ask for the missing push messages.

 

This is the only solution I have.

 

 

Please use plain text.
Trusted Contributor
gazier20
Posts: 120
Registered: ‎10-25-2010
My Device: Not Specified

Re: Push message - Switch off

Do you really try to switch off your phone then send 50 push messages with 5KB each ?

 

I try and try and my blackberry always reboots after 10 or 15 push messages received even if I use the Blackberry Torch (OS 6.0)

 

Could you confirm it works on your side ?

Please use plain text.
Trusted Contributor
gazier20
Posts: 120
Registered: ‎10-25-2010
My Device: Not Specified

Re: Push message - Switch off

Is there a way to avoid the reboot ?

 

I mean : Is there a way to catch an exception when the phone is working too much and is going to reboot ?

 

Here is an example of my push message :

 

--StartNote20319<F>FDA approves GSK's Benlysta, Lonza makes it<F>Lonza<F>Pharmaceuticals & biotechnology<F>The FDA yesterday approved Benlysta for systemic lupus erythematosus (SLE). Lonza has a long-term contract to supply that anti-body to GSK once the capacities of Human Genome Sciences have been fully used.     <F>The approval comes one day ahead of the PDUFA day and is for adult patients with active autoantibody-positive SLE who are receiving standard therapy. Human Genome Sciences (the originator) suggested that the drug  will initially target a US population of 200,000 with moderate-to-severe form of the disease. The patient number is the same as we have in our model as the peak Benlysta population. Depending on off-label use the addressable US  patient base could be bigger up to 1.5m when also including the mild-to-moderate form of the disease.    <F>While the specific impact on short-term numbers is difficult to model (given the contract terms with GSK and HGS, the news is very positive. It derisks one of its key pipeline projects required to ensure high utilization of its biopharma manufacturing back-bone medium-term. A big compound can add up to 5% to Lonza's EBIT potential. Hence, a positive reaction in the low-to-mid single digit %pt range is justified today.<F>2011/03/10 08:41:04<F>CHF76.90<F>CHF90.00<F>Switzerland<F>Small & Mid-Cap<F>Buy<F>Buy<F>LONN.S<F>LONN VX<F>CHF4,070(m)<F>CHF5,227(m)<F>2.6%<F>0.6%<F>DJ Stoxx 600<F>+41 43 333 6606<F>florian.gaiser@keplercm.com<F>/9j/4AAQSkZJRgABAQEANgA2AAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABLAEsDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztL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GwVl+IbCPUdCu4JOPkLK2PukDOa1Kayh1KsAVIwQe9C0B6nklhbw20S26ALGnp0qGTUlN41vbplI+ZHxkL7fWtnxPpiaXf+VbKUhkTcnOcHoRXIwGbTUWOS3DxuxDT7/4v9r/ABrda6mT00LWpapYpas8knJ69sfnWVZ6vC8oQfvIWAw2MYPpUmp2CTKLk2okjxkMsqFcZx1zWCks1zd/Zre0dVTB35G3n0I6mqJOkuJIvMXy+B3HpXa/Cfw/JpWkT30pI+1kLGp7IpOD+Of0rh9E0yfV9dh05X2s/wB9wM7QBya9z0+zj0/T4LOL/VwoEUnqcd6zqPoXFdSzRRRWRoFFFFAHHePlP2ezcdmYfoP8K5G2KPCyNhgedprtfHaltHiZRnZMMn04Irzl5HgjMysOOoraGxlLcy9ReSO5aJYVCE4Hy1D5hto84+YjipLvxBAxZWYZrBmvJLufamdp4AA61ZNz0P4Wv5viaZjyfszEn1O5a9hrynwNpcuhyJfXIKyycFO6ofX3/wAK9USRJEDIwZT0IOaxqbmkNh1FFFQWQSXKR57kdqgeeWQHbwPap/s0TEsU5J9TTvJjxjb+tMRQltY7q2kt503xyDDA96808Q6FcaTM0fL28mfLlPf2Pof5162IkHRf1qlfaRZX80UtzE7tFnYPNcLz6qDg/iKcZWFJXR4FZ+DdR1S6ItotqZ+eVuFUe5/pXeaH4RstG2yFfPuR1lcdD/sjt/OvRrewtobcQRx4jXOAWJ/U0HTbQ9YR/wB9GrcyVFI5fbmprNprcGSFyqk9B/hXRf2baD/liPzNO+xW2APKGB05NS5DRTt9WPS5UAf3l/wrTWRXUMrAqeQRVc2Fr/zyH5mp44kijCIuFHQZqSrn/9k=<F>FY ending: 31/12;2010;2011E;2012E;  Sales (CHFm);2,680.0;2,760.0;2,982.6;  EBITDA;643.0;652.2;731.8;  EBIT;374.0;389.2;460.7;  Pretax profit;325.0;333.4;392.4;  Net profit (adj);315.0;322.7;374.4;  EPS (adj);6.09;6.28;7.28;  DPS;2.15;2.19;2.52;  PE;13.4;12.3;10.6;  EV/sales;2.0;1.9;1.7;  EV/EBITDA;8.5;8.0;7.0;  EV/EBIT;14.6;13.4;11.2;  Net debt/EBITDA;1.8;1.8;1.5;  FCF Yield;4.8%;5.1%;5.2%;  Net dividend yield;2.6%;2.8%;3.3%;  <F>Florian<F>Gaiser<F>1<F>2011/03/10<F>EV<F>1<F><endNote>

 

I have the picture of the writer encrypted. It could be the problem,no ?

 

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Push message - Switch off

As an update... We have been trying to reproduce the issue on devices here without any luck so far.. 

 

I'm wondering if it is a volume and timing issue that we are not accurately reproducing..

 

As a work around... Just thinking out loud...

 

What happens if you create a global array and insert each new push message into the global array.. Then have a timer in the background that is triggered when you receive new messages that processes the data in small chunks.. basically process the top X messages and then set another setTimeout to process the next X messages.

 

I'm just trying to think of some work arounds until we can get to the root of the problem.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Trusted Contributor
gazier20
Posts: 120
Registered: ‎10-25-2010
My Device: Not Specified

Re: Push message - Switch off

I'm still working on this problem.

 

The size of my push message is 4KB. If I remove the encrypted picture, the size is 2KB.

 

I just tryed to send 50 push messages and it seems to work with 2KB each. I'm modifying my application.

 

If you have any news, let me know because I confirme that it doesn't work properly with the 8520 (OS 5.0 0.681)

 

Your idea is interesting. I'll see what I can do

Please use plain text.
Developer
abarber
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: Push message - Switch off

Hi

 

As another test have you tried placing a 1 sec delay between each push?

 

Cheers

 

Andrew

Please use plain text.
Trusted Contributor
gazier20
Posts: 120
Registered: ‎10-25-2010
My Device: Not Specified

Re: Push message - Switch off

abarber, 

 

Each morning between 7:00 and 9:00am, we send 50 push messages.

The problem is when a user switch on his mobile at 10:00am, it receives the 50 messages in 3-5s !!!

I can't control that. It manages by the BIS,BES.

 

I'd love to be able to say : "Please resend the messages with 3s between each push".

 

 

 

Please use plain text.
Developer
abarber
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: Push message - Switch off

Hi

 

Are you sure this is only related to the push and not the Database insert?

 

Is this still occuring when there is no database insert?

 

Cheers

 

Andrew

Please use plain text.