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
Contributor
Posts: 35
Registered: ‎07-07-2011
My Device: Torch
My Carrier: AT&T
Accepted Solution

onHardwareKey broken in WebWorks 2.2 SDK

The blackberry.system.event.onHardwareKey API is exhibiting issues when an application is built using WebWorks 2.2 SDK.  After registering button call backs, the first press of a button is detected. However, if the same button is pressed a second time (or more) those subsequent presses do not invoke the call back.  If a different button is pressed, its call back is invoked.  Pressing the first button again will then correctly invoke the call back.  It appears that repeated presses of a single button are not resulting in repeated invocations of the call back. 

 

Additionally, I am no longer able to return the button to the default behavior by clearing the call back with null.  Prior to SDK 2.2, passing null to onHardwareKey for a button reverted the button to default behavior.  This is no longer happening with SDK 2.2.

 

The above behavior was experienced on a Torch 9800 device.  My experience in the simulators (OS 5, 6, 7) has been worse and inconsistent.  On the simulators, there are times when the call back is successfully invoked and other times when it is not.  It has been proven too random to describe so I described the behavior on an actual device.

 

I've included a sample html file below which provides a way to register / unregister call backs for the buttons:

 

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" id="viewport" content="width=device-width,height=device-height,initial-scale=1.0,user-scalable=no">
    <script type="text/javascript">

        function handleMenu() { alert("Caught menu button"); }
        function handleBack() { alert("Caught back button"); }
        function handleVolumeUp() { alert("Caught volume up button"); }
        function handleVolumeDown() { alert("Caught volume down button"); }
        function handleCvnOne() { alert("Caught convenience button 1"); }
        function handleCvnTwo() { alert("Caught convenience button 2"); }
        function handleStartCall() { alert("Caught start call button"); }
        function handleEndCall() { alert("Caught end call button"); }

        function registerListeners() {
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, handleBack);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_MENU, handleMenu);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_CONVENIENCE_1, handleCvnOne);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_CONVENIENCE_2, handleCvnTwo);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_STARTCALL, handleStartCall);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_ENDCALL, handleEndCall);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_VOLUMEDOWN, handleVolumeDown);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_VOLUMEUP, handleVolumeUp);

            document.getElementById('replace').innerHTML = "Listeners registered";
        }

        function unregisterListeners() {
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, null);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_MENU, null);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_CONVENIENCE_1, null);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_CONVENIENCE_2, null);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_STARTCALL, null);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_ENDCALL, null);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_VOLUMEDOWN, null);
            blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_VOLUMEUP, null);

            document.getElementById('replace').innerHTML = "Listeners unregistered";
        }
    </script>
    <title>Test Button Capture</title>
  </head>
  <body>
    <p id="replace">No button listeners registered</p>

    <input type="button" value="Register Events" onclick="registerListeners();return false;" />
    <input type="button" value="Unregister Events" onclick="unregisterListeners();return false;" />
  </body>
</html>

 

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: onHardwareKey broken in WebWorks 2.2 SDK

thanks for reporting this.  we have some folks looking into this issue now.

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Contributor
Posts: 16
Registered: ‎06-29-2011
My Device: 9800
My Carrier: -

Re: onHardwareKey broken in WebWorks 2.2 SDK

for me, when I register for the back button, whenever I press it the app just crashes

New Developer
Posts: 46
Registered: ‎01-14-2011
My Device: BB10
My Carrier: ATT

Re: onHardwareKey broken in WebWorks 2.2 SDK

same issue here, I am never getting the callback

Mike
marcucio.com - productivity apps
http://marcucio.com
Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: onHardwareKey broken in WebWorks 2.2 SDK

[ Edited ]

The issue has been found and resolved.. it had to do with a maximum number of concurrent AJAX connections that were allowed to be open.  We are using AJAX under the sheets to provide an event channel back into JavaScript.  The system event object is using this new plumbing and by trapping all the events it ties up all the AJAX channels.

 

I'll double check with the guys to see if this fix has been pushed upstream in the github repo.  We now have build and patch instructions up in github so that you can grab the latest code at any time.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Developer
Posts: 46
Registered: ‎01-14-2011
My Device: BB10
My Carrier: ATT

Re: onHardwareKey broken in WebWorks 2.2 SDK

let us know when it is pushed to github, I will try it out.

Mike
marcucio.com - productivity apps
http://marcucio.com
Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: onHardwareKey broken in WebWorks 2.2 SDK

The code changes should now be up in the "Next" branch.

 

https://github.com/blackberry/WebWorks/tree/next

 

You can clone the repo and run the build instructions to patch your install with the fixes.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Highlighted
Contributor
Posts: 35
Registered: ‎07-07-2011
My Device: Torch
My Carrier: AT&T

Re: onHardwareKey broken in WebWorks 2.2 SDK

I have confirmed that this issue is resolved in WebWorks SDK v2.3.

 

Thanks.