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
Highlighted
New Developer
Posts: 36
Registered: ‎12-12-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Unable to handle back button event in BBOS

Hi,

 

I'm unable to handle back button press event in BBOS on first page of application.

 

When i press back button want to show message to close app but unable to do so.

 

using below code to handle back button event.

 

function trapForBackKey() {
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, handleBack);
}

function handleBack() {
alert("handle back button");
}

 

Thanx in advance.

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Unable to handle back button event in BBOS

When are you calling trapForBackKey? Are you calling it at startup to register the event listener?

Have you added this feature to your config.xml?
<feature id="blackberry.system.event" />

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
New Developer
Posts: 36
Registered: ‎12-12-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Unable to handle back button event in BBOS

Hi Oros,

 

Yes i'm calling it on startup and i have <feature id="blackberry.system.event" /> in config.xml file.

New Developer
Posts: 36
Registered: ‎12-12-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Unable to handle back button event in BBOS

If possible can you share some sample code.

Developer
Posts: 49
Registered: ‎05-02-2013
My Device: Z 10
My Carrier: airtel

Re: Unable to handle back button event in BBOS

Hi ,

 

Please check bbui samples for smartphone. You will get the same code from bbui.js

New Developer
Posts: 65
Registered: ‎08-07-2013
My Device: Blackberry Torch 9800
My Carrier: Mobile App Development

Re: Unable to handle back button event in BBOS

Hi,

 

Don't use blackberry.system.event code inside the trapForBackKey() function. now you can use the below code, i hope it works.

 

code:

blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,handleback);
    
    function handleback() {
        alert("Back Button Clicked");

        //window.location = "register.html";
    }