PDA

View Full Version : Blackberry Back Button in Phonegap no longer working when Sencha added



treike
6 Feb 2012, 7:18 AM
I've created a Sencha Touch App and I am using this with Phonegap to generate a Blackberry App.

I want to make use of the hardware back button, which is possible via BB Webworks and works, but only as long as I don't add Sencha Touch. It works fine when not using Sencha Touch, but the event seems not to be caught when Sencha Touch js-files are added.





<script type="text/javascript">
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,
function() {
alert("back");
//history.back();
return true;
});
</script>


Any clues why?

Thanks!

mitchellsimoens
6 Feb 2012, 8:22 AM
I wouldn't see any reason how we would prohibit a physical button.

treike
6 Feb 2012, 8:44 AM
I can't see any reason too, but it's just like that.

I've tested:

A clean app, no code of myself included (except the event listener js).

I just added only sencha-touch.js and then the eventlistener shows the defined "back"-alert.

Then I added the ST "HelloWorld" example js and as soon as "Hello World" is shown on the canvas the evenlistener is no longer catching the event, the app closes. Before Hello World is shown, the event listener still shows the alert.

I think that as soon as Ext.Application or Ext.regApplication is called, the BB back button is no longer working as expected.

treike
6 Feb 2012, 11:28 PM
Would it help if I send a zip of my test code somewhere?

treike
9 Feb 2012, 7:10 AM
So, to bump this one up.

I think it is very obvious that Sencha Touch is doing something that prevents the BB BackButton event.

This is working, I always catch the event and can display the alert.


<!DOCTYPE html>
<html>
<head>
<title>Back Test</title>
<script src="lib/sencha-touch-debug-w-comments.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">


/* new Ext.Application({
launch: function() {
new Ext.Panel({
fullscreen: true,
html: 'Hello World!'
});
}
});*/


</script>

<script>
function trapBackKey(){
alert("trapped");
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,
function() {
//window.history.back();
alert("menu");
return false;
});
}

trapBackKey();
</script>
</head>
<body>
</body>
</html>


Commenting the "new Ext.Application" back in, it's no longer working. For a short amount of time I can catch the event, until shortly before "Hello World" is displayed. When I click the back button after the display of "Hello World" the app closes instead of showing the alert.



<!DOCTYPE html>
<html>
<head>
<title>Back Test</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=1.0;" />

<script src="lib/sencha-touch-debug-w-comments.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">


new Ext.Application({
launch: function() {
new Ext.Panel({
fullscreen: true,
html: 'Hello World!'
});
}
});


</script>

<script>
function trapBackKey(){
alert("trapped");
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,
function() {
//window.history.back();
alert("menu");
return false;
});
}

trapBackKey();
</script>
</head>
<body>
</body>
</html>


So there has to be something when loading the Ext-App that prevents the blackberry event, isn't it?

Maybe someone could just give me a hint or something else?

treike
9 Feb 2012, 11:39 PM
So for anyone being lucky do develop for Blackberrys :-|:
While I did get it to work without futher ado with a jQuery mobile app, I couldn't get it to work for Sencha Touch the way described in den Blackberry documents and above.

But I found a workaround for this one.

I found out that the BB BackButton is mapped in Javascript to a KeyCode of 27 (escape). So I defined a keydown listener and handled that event appropriately. But you have to prevent further propagation of the event. Otherwise the app still exits instead of going back.

Hope this helps someone else, too.

composer47
29 Jan 2013, 1:22 PM
I'm not sure why, but whenever Sencha animates a Sheet or View, the back button breaks. The solution is to turn off animations for Blackberry.

You can see how to do that (and other Blackberry tips) here:

http://www.sencha.com/forum/showthread.php?252232-GUIDE-Deploying-Sencha-Touch-2.1-as-a-Blackberry-native-apps-%28Webworks%29