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
Posts: 100
Registered: ‎01-13-2012
My Device: Simulator - 9800
My Carrier: Simulator

Pressing Back Exits Application

There is a button that opens a new page on my app.

 

Page 1  ---------- (button click) ------------>   Page 2

 

When I press back on the Ripple Emulator, the previous page is shown ( the page with the button).

 

Page 1 <---------- (press Back) -------------  Page 2

 

However when I load and run the App on my blackberry things are different. Pressing back does not get me back to my previous page but exits the application. Does anyone know if this is suppose to happen or what is going on here? I would need it to return to my previous page but it is not happening on the device. Is there any code I need to put to make this work?

 

Thanks

 

 

Developer
Posts: 214
Registered: ‎01-07-2011
My Device: Bold 9900
My Carrier: Rogers

Re: Pressing Back Exits Application

Are you currently using any frameworks to manage your pages?

--
Rory (@roryboy)
Click "Accept as Solution" if post solved your original issue. Give like/thumbs up if you feel post is helpful
Contributor
Posts: 17
Registered: ‎01-30-2010
My Device: Bold 9900
My Carrier: Claro - Republica Dominicana

Re: Pressing Back Exits Application

Same thing is happening to me Rory. On ripple everything works fine but on the phone well that's another story. I'm using bbUI.

Also (idk if I should open a new threat but), when using the ads API I can't get the swipe menu to work on my playbook, I know that the playbook doesn't support this api as of yet but if I choose to display the ads on my playbook's app, swiping down does nothing. Same thing with focused navigation on my phone when testing my app.

I did as you suggested me Rory on twitter (@lacahe), I'm putting the ads on each screen rather than the index file, but on the playbook sim they only show when the index and menu screens are loaded the first time but this isn't the case with the remaining screens.

Funny of it all, all of the above run perfectly and I do mean perfectly on the ripple emulator.

Workflow is something like this:

(I'm using the correct syntax in my app lol)

index.html+menu.html-----> <button> onclick=pushnextscreen+displayAd()--------> nextscreen.html

                 ^                       <---- <back button> onclick=pushindex+displayAd()                           ^

    api works  on launch                                                                                                api doesn't work (except on ripple)

 

ps:I'm using the trial ID with the ads API

Trusted Contributor
Posts: 100
Registered: ‎01-13-2012
My Device: Simulator - 9800
My Carrier: Simulator

Re: Pressing Back Exits Application

I'm just using ordinary HTML/CSS/Javascript in my index file. The only blackberry portion I have at the moment in my index.html file is

 

<meta name="viewport" content="width=device-width,target-densitydpi=device-dpi,user-scalable=no,initial-scale=1.0">

 and the config.xml file uses

 

  <feature id="blackberry.ui.dialog"/>

 but I'm not sure if that would cause the issue. 

 

 

 

Developer
Posts: 214
Registered: ‎01-07-2011
My Device: Bold 9900
My Carrier: Rogers

Re: Pressing Back Exits Application

Have you tried adding a back button handler? (http://glpr.ca/IeGZPW) You could add a piece of JS that sends the user back to the last page visited.

<script type="text/javascript">
  function trapForBackKey() {
    blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, handleBack);
  }

  function handleBack() {
    alert("handle back button");
  }
</script>

I am not sure what the default back button behaviour is if it isn't handled in code, maybe someone else can chime in on that. 

 

Also bbUI.js is a good barebones framework that RIM has made available, it allows you to easily manage your screens and handles the back button for you, you might want to check it out too.  (https://github.com/blackberry/bbUI.js)

 

--
Rory (@roryboy)
Click "Accept as Solution" if post solved your original issue. Give like/thumbs up if you feel post is helpful
Developer
Posts: 214
Registered: ‎01-07-2011
My Device: Bold 9900
My Carrier: Rogers

Re: Pressing Back Exits Application

Can you PM me the snippet you are using to display the ads API on playbook? I can drop it into one of my apps to see if I can replicate the problem you are having. It may have odd results because it is not officially supported.

Probably better to start a new thread on it to see if other people are having issues (+ help people in the future who may have problems)
--
Rory (@roryboy)
Click "Accept as Solution" if post solved your original issue. Give like/thumbs up if you feel post is helpful
Trusted Contributor
Posts: 100
Registered: ‎01-13-2012
My Device: Simulator - 9800
My Carrier: Simulator

Re: Pressing Back Exits Application

Thank you for the information this is probably what I'll have to use. Strangly enough it isn't working in Ripple. I copy pasted the code snippet to test it out in my index.html file and it has no effect. I've tried calling 

 

trapForBackKey();

but again no effect when pressing back in Ripple. Also placing this code in my initial javascript function that runs at the start of the app:

 

blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, alert('TEST'));

but then the entire startup function does not run for some reason. I was hoping for an alert of 'TEST' when I pressed the back button.

 

 

Developer
Posts: 60
Registered: ‎06-08-2011
My Device: n/a
My Carrier: n/a

Re: Pressing Back Exits Application

[ Edited ]

 I am using bbui and the back button is working in the Ripple Chrome extension and on OS6 and OS7 devices. If you are using the bbui, then check out the documentation (scroll down to the Managing Screens section) https://github.com/blackberry/bbUI.js. At the very least you could check out their implementation.

 

"To open a new screen in an appliction using bbUI you simply call bb.pushScreen('mypage.htm', 'mypagename'). To close the top screen you simply call bb.popScreen(). The toolkit is designed to use the Application Event WebWorks API so that it can trap the "back" hardware key and automatically handle popping the last screen off of the stack.

 

If you want to override the back button handling, and substitute it with your own handler, you can simply call bb.assignBackHandler(callback) and your callback function will now be invoked when the back button is clicked. It is then up to you to handle all back button navigation."

 

 

Highlighted
Developer
Posts: 60
Registered: ‎06-08-2011
My Device: n/a
My Carrier: n/a

Re: Pressing Back Exits Application

Do you have this feature in your config.xml file?

 

<feature id="blackberry.system.event" />

 

https://bdsc.webapps.blackberry.com/html5/apis/blackberry.system.event.html

Trusted Contributor
Posts: 100
Registered: ‎01-13-2012
My Device: Simulator - 9800
My Carrier: Simulator

Re: Pressing Back Exits Application

I didn't have the feature tag in the config file I can't believe I overlooked that. When I press back I want it to navigate back to my index.htm file. So far I have the code below:

 

function handleBack()
{
    alert("handling back button");
    document.location.href="index.htm"; 
}
trapForBackKey();

 But its loading http://developer.blackberry.com/ripple/index.htm and not my index.htm in my app folder. I've tried /index.htm and ../index.htm but none work. I originally launched the new page by doing 

 

document.location.href="info.htm?name="+string;

 which now I want to return to index.htm when I press back. Do you know how to achieve this?