06-12-2012 03:15 AM
try{
blackberry.system.event.onHardwareKey(blackberry.s ystem.event.KEY_BACK, handleBack);
}catch(e){
alert('exception occ'+e);
}
function handleBack(){
alert('i m here');
}This is my code.
It crashes my app in os6.
Has anybody come across with this issue.
I am using webworks sdk 2.3.1.5.
06-12-2012 06:51 PM
Hi there,
It looks like you are declaring a function after the try (i.e. a function inside of a function.) Perhaps I am misunderstanding what I see though. But it looks to me like you would need to move the
function handleBack(){
alert('i m here');
}
Code so that it is not inside of another function.
Does the application crash when you hit the back key? Or simply when it is loading?
06-13-2012 01:56 AM
Hi,
handleBack function is not inside try.
App starts,it shows first screen and then app gets closed.
But it works in OS 7 phone.
Is there any issue with this API??
06-13-2012 11:00 AM
As far as I know, this API shouldn't cause that sort of crash.
Have you had a chance to use Web Inspector to step through and confirm which line is crashing the app specifically? If you remove this code from your application, does it run normally then?
06-14-2012 01:51 AM
<html>
<head>
<script type='text/javascript'>
try{
blackberry.system.event.onHardwareKey(blackberry.s ystem.event.KEY_BACK, handleBack);
}catch(e){
alert('exception occ'+e);
}
function handleBack(){
alert('i m here');
}
</script>
</head>
<body>
Home Page
</body>
</html>I was using this code in my app where it crashes app.
So i made a new app which has only this code and this crashes my app.
And when I remove this line, my app works fine.
Thats why I was asking whether this API has issues with OS 6.
06-14-2012 12:20 PM
Ah, I think I see what the issue may be. You are referencing the WebWorks API before the document has loaded, which I've seen cause issues before. What about something like this?
config.xml
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0.0" id="back" xml:lang="en"> <name>back</name> <author>Oros</author> <access subdomains="true" uri="*"/> <content src="index.html"/> <feature id="blackberry.system.event" /> </widget>
Note that we must include the blackberry.system.event feature.
index.html
<!DOCYTPE html>
<html>
<head>
</head>
<body>
<p>Home Page</p>
<script type="text/javascript">
/*global window, document, console, alert, blackberry */
function handleBack() {
"use strict";
try {
alert("I'm here.");
} catch (err) {
console.write("handleBack: " + err);
}
}
function ready() {
"use strict";
try {
window.removeEventListener("DOMContentLoaded", ready, false);
blackberry.system.event.onHardwareKey(blackberry.s ystem.event.KEY_BACK, handleBack);
} catch (err) {
console.write("ready: " + err);
}
}
window.addEventListener("DOMContentLoaded", ready, false);
</script>
</body>
</html>