Paul Maddox created CB-7439:
-------------------------------

             Summary: Android 4.4 androidExec online events callback messages 
delayed
                 Key: CB-7439
                 URL: https://issues.apache.org/jira/browse/CB-7439
             Project: Apache Cordova
          Issue Type: Bug
          Components: CordovaJS
    Affects Versions: 3.5.0
         Environment: Android 4.2 + Android 4.4 (presumably others)
            Reporter: Paul Maddox


I have an app where I'm calling:

{noformat}
navigator.notification.confirm
{noformat}

from org.apache.cordova.dialogs 0.2.9. The dialog is displayed fine, however on 
my Android test devices upon pressing a dialog button my callback function 
sometimes isn't executed.

I believe I've tracked this down to an issue with Android's JS implementation, 
however I don't have quite enough knowledge of Cordova to ascertain the root 
cause or fix it properly.

Naturally, navigator.notification.confirm calls androidExec. This in turn makes 
a native API call. The thing I'm unsure about is the following events:

{noformat}
    // The network module takes care of firing online and offline events.
    // It currently fires them only on document though, so we bridge them
    // to window here (while first listening for exec()-releated online/offline
    // events).
    window.addEventListener('online', pollOnceFromOnlineEvent, false);
    window.addEventListener('offline', pollOnceFromOnlineEvent, false);
    cordova.addWindowEventHandler('online');
    cordova.addWindowEventHandler('offline');
    document.addEventListener('online', proxyEvent, false);
    document.addEventListener('offline', proxyEvent, false);
{noformat}

When I press one of the confirm dialog buttons the event listener 
pollOnceFromOnlineEvent is called, which retrieves messages from the native API 
and processes them accordingly. However it seems the online event doesn't 
always work. I'm not sure why we're using the online event in the first place 
though..

Now, there's a nasty side-effect as well. In androidExec itself, after making 
the native API call, we actually call processMessages, so we may get our 
callback, but delayed!

What should happen:

{noformat}
call confirm() --> calls androidExec --> calls processMessages (no messages) 
--> user button press --> online event --> calls pollOnceFromOnlineEvent --> 
calls processMessages --> calls callback
{noformat}

What actually happens is:

{noformat}
call confirm() --> calls androidExec --> calls processMessages (no messages) 
--> user button press --> NO online event

.. time passes ..

call confirm() --> calls androidExec --> calls processMessages (got message!!)  
--> calls callback --> user button press --> NO online event

.. and the bad cycle continues.
{noformat}

I believe some points to consider are:

* Is the online event being used properly
* The android JS implementation seems to support polling mode - should we be 
using this?
* Should androidExec be processing messages immediately after the native API 
call?

I've put this as an issue with 3.5.0, as that's what my app is running and can 
readily repro it, however it also existed on 3.4.x.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to