使用 LocationListener 的 BlackBerry 应用程序在 OS 6 上冻结

发布于 2024-10-28 11:49:54 字数 1562 浏览 3 评论 0原文

我有一个 Java 应用程序,它使用 LocationProvider API 在应用程序启动时注册 LocationListener 并在关闭应用程序时取消注册。将应用程序置于后台并将其返回前台时也会这样做。

这在大多数情况下工作得很好,但我最近在不同的设备上遇到了应用程序冻结/挂起的情况(例如,我可以在我的 BlackBerry Torch OS 6 上重现它,似乎这种情况在 OS 6 上发生得更频繁)设备)。

打开应用程序,关闭它重新打开它,当我尝试关闭它时,它冻结再次。我无法再关闭它了。我必须使用“切换应用程序”功能转到另一个应用程序(通过按住菜单按钮或按绿色或红色按钮)。

之后,我收到一条错误消息,指出应用程序没有响应并已关闭。

代码如下所示:

public void activate() {
    if (ApplicationPermissionsManager.getInstance().getPermission(14) == ApplicationPermissions.VALUE_ALLOW) {
        startLocationProvider();
    }
}

public void deactivate() {
    if (ApplicationPermissionsManager.getInstance().getPermission(14) == ApplicationPermissions.VALUE_ALLOW) {
        stopLocationProvider();
    }
}

public boolean onClose() {
    stopLocationProvider();
    System.exit(0);
    return true;
}

public void startLocationProvider() {
  try {
    locationProvider = LocationProvider.getInstance(new BlackBerryCriteria(GPSInfo.GPS_MODE_ASSIST));
    if (locationProvider != null) {
      locationProvider.setLocationListener(new LocationListenerImpl(), 10, 9, -1);
    }
  } catch (Exception le) {
    // log it           
  }
}

public void stopLocationProvider() {
  if (locationProvider != null) {
    try {
      locationProvider.setLocationListener(null, -1, -1, -1);
      locationProvider = null;
    } catch (Exception se) {
      // log it             
    }
  }
}

I have a Java Application that uses the LocationProvider API to register a LocationListener at startup of the application and deregisters it when closing the application. It does so too when putting the application in the background and getting it back to the foreground.

This works quite well in most cases but I am experiencing freezes/hangs of the app lately on different devices (eg I could reproduce it on my BlackBerry Torch OS 6, seems like it happens more often on OS 6 devices).

I open the app, close it, reopen it and it freezes when I try to close it again. I can not close it anymore. I have to use the "switch application" functionality go to another app (by holding the Menu button or pressing the green or red button).

After I while I get an error message saying that the application did not respond and was closed.

The code looks like the following:

public void activate() {
    if (ApplicationPermissionsManager.getInstance().getPermission(14) == ApplicationPermissions.VALUE_ALLOW) {
        startLocationProvider();
    }
}

public void deactivate() {
    if (ApplicationPermissionsManager.getInstance().getPermission(14) == ApplicationPermissions.VALUE_ALLOW) {
        stopLocationProvider();
    }
}

public boolean onClose() {
    stopLocationProvider();
    System.exit(0);
    return true;
}

public void startLocationProvider() {
  try {
    locationProvider = LocationProvider.getInstance(new BlackBerryCriteria(GPSInfo.GPS_MODE_ASSIST));
    if (locationProvider != null) {
      locationProvider.setLocationListener(new LocationListenerImpl(), 10, 9, -1);
    }
  } catch (Exception le) {
    // log it           
  }
}

public void stopLocationProvider() {
  if (locationProvider != null) {
    try {
      locationProvider.setLocationListener(null, -1, -1, -1);
      locationProvider = null;
    } catch (Exception se) {
      // log it             
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2024-11-04 11:49:54

在事件线程上调用位置侦听器(您不为其提供代码)。如果在事件线程上调用的方法阻塞时间过长,则会导致您遇到挂起。操作系统最终将终止此类未能响应的应用程序。您需要查找可能需要很长时间才能执行的 LocationListenerImpl 片段,或者发布该代码以便我们查看。

The location listener (which you don't provide code for) is called on the event thread. If a method invoked on the event thread blocks for too long it causes the hanging you are experiencing. The OS will eventually kill such applications for failing to respond. You need to look for segments of LocationListenerImpl that could take a long time to execute, or post that code so we can have a look at it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文