简体   繁体   中英

Blackberry WebWorks SMS Listener Exception

Specs: WebWorks 2.2, Curve 9330 OS 6 Simulator and Device

We'll, I've tried just about everything and I can't figure this out. My application has a main page (index.html) and a background page (listener.html), as specified here:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" 
   xmlns:rim="http://www.blackberry.com/ns/widgets" 
   version="1.0.0.0" rim:header="SimpleSMS">
   <name>SimpleSMS</name>
   <description>Simple SMS</description>
   <content src="index.html">
       <rim:background src="listener.html" runOnStartup="true" />
   </content>
   <rim:navigation mode="focus" />
   <access subdomains="false" uri="http://jsconsole.com"/>
   <feature id="blackberry.message.sms" />
   <feature id="blackberry.app" />
   <feature id="blackberry.io.dir" />
   <feature id="blackberry.io.file" />
   <feature id="blackberry.utils" />
</widget>

The listener.html looks like this:

<!DOCTYPE html>
<html>
    <head>
    <script type="text/javascript" src="message_db2.js"></script>
    <script type="text/javascript">
    </script>
    </head>
    <body onload="initializeListener();">
    </body>
</html>

The initializeListener() function is as follows:

function initializeListener() {
    blackberry.message.sms.isListeningForMessage = true;
    blackberry.message.sms.addReceiveListener(messageListener);
}

The issue: When I install my app, and the listener starts running, my app can receive text messages without problems. As soon as I open the main application, the problems begin. If I just minimize the app to the background using the back or end button, the next sms received causes an exception. If I close the app through the menu, there's no exception, but the listener ceases to function. I have commented all code in messageListener and index.html does absolutely nothing but display some html. There is almost no documentation regarding having a background page. Does anyone have any ideas? Thanks in advance.

Could it be that webworks is going to these different pages and discarding everything that's in the previous page? (Like what happens to a form you fill out when you go to a new page in your browser)

Maybe you need to make use of Application Events to check when the app goes to the Foreground or Background; Maybe double check isListeningForMessage?

I'm thinking of something like

function onFG()
{
  if (!blackberry.message.sms.isListeningForMessage)
  {
    blackberry.message.sms.isListeningForMessage = true;
    blackberry.message.sms.addReceiveListener(messageListener);
  }
}

blackberry.app.event.onForeground(onFG);

You can also make use of isForeground boolean if you need to have your code distinguish where it is running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM