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
kundan4776
Posts: 10
Registered: ‎03-22-2012
My Device: 9380
My Carrier: Vodafone

BAck Key event crashes app os 6

try{
			blackberry.system.event.onHardwareKey(blackberry.system.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.

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BAck Key event crashes app os 6

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?


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.
Please use plain text.
Contributor
kundan4776
Posts: 10
Registered: ‎03-22-2012
My Device: 9380
My Carrier: Vodafone

Re: BAck Key event crashes app os 6

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??

 

 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BAck Key event crashes app os 6

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?


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.
Please use plain text.
Contributor
kundan4776
Posts: 10
Registered: ‎03-22-2012
My Device: 9380
My Carrier: Vodafone

Re: BAck Key event crashes app os 6

<html>
<head>
<script type='text/javascript'>
try{		 	         
blackberry.system.event.onHardwareKey(blackberry.system.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.

 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BAck Key event crashes app os 6

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.system.event.KEY_BACK, handleBack);
				} catch (err) {
					console.write("ready: " + err);
				}
			}

			window.addEventListener("DOMContentLoaded", ready, false);
		</script>
	</body>
</html>

 


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.
Please use plain text.