简体   繁体   English

Blackberry WebWorks SMS侦听器异常

[英]Blackberry WebWorks SMS Listener Exception

Specs: WebWorks 2.2, Curve 9330 OS 6 Simulator and Device 规格:WebWorks 2.2,Curve 9330 OS 6模拟器和设备

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: 我的应用程序有一个主页(index.html)和一个背景页(listener.html),如下所示:

<?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: listener.html如下所示:

<!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: initializeListener()函数如下:

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. 我已经注释了messageListener中的所有代码,但index.html绝对不做任何事情,只显示一些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? 可能是Webworks会转到这些不同的页面并丢弃上一页中的所有内容吗? (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? 也许仔细检查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. 如果需要使代码区分运行位置,则也可以使用isForeground布尔值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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