简体   繁体   English

黑莓手机后台监听线程

[英]Blackberry background listener thread

Hey everyone! 嘿大家! I am new to blackberry programming although I do have some java experience, with c# being my main language). 尽管我确实有一些 Java经验,但我还是黑莓编程的新手,我主要的语言是c#。

What I am trying to do is write a thread that will run on system startup and exist in the background as a listener. 我想做的是编写一个将在系统启动时运行并作为侦听器在后台存在的线程。

I would like my app to implement KeyListener and basically sit in the background while the phone is on and track a histogram of how many times each button has been pressed. 我希望我的应用程序实现KeyListener并基本上在手机开机时位于后台,并跟踪每个按钮被按下了多少次的直方图。 I'm currently running on the simulator so for now I'm just going to have it print to the console when it gets a key. 我目前正在模拟器上运行,所以现在我将在获得密钥时将其打印到控制台。

I have been able to implement a keyListener in a UIApplication but it only works while the app is loaded. 我已经能够在UIApplication中实现keyListener,但是它仅在加载应用程序时有效。

Here is the app that I have currently 这是我目前拥有的应用

public class CustomApp extends UiApplication
{
    private keyListenerThread listener;
    public stati void main(String[] args)
    {
        CustomApp myApp = new CustomApp();
        myApp.enterEventDispatcher();
    }

    public CustomApp()
    {
        listener = new KeyListenerThread();
        this.addKeyListener(listener)

        //.....other GUI setupthings....

        pushScreen(mainScreen);
    }

    private class KeyListenerThread extends Thread implements KeyListener
    {

        public KeyListenerThread()
        {

        }

        public boolean keyDown(int arg0, int art1)
        {
            System.out.println("button pressed!!");
            }

        //...other keylistener methods
    }

this only works if the app is open though. 不过,只有在应用打开的情况下,此方法才有效。 so its not really what i'm trying to achieve. 因此,这并不是我想要达到的目标。 If anyone can point me in the right direction i'd appreciate it! 如果有人能指出我正确的方向,我将不胜感激!

EDIT: 编辑:

I have found this example that shows partially what I'm looking for: http://supportforums.blackberry.com/t5/Java-Development/Allow-a-background-listener-to-detect-and-update-a-GUI/ta-p/442907 The one problem is that im doing this in the simulator and I dont know how to exercise this code so that I can really debug through how its working. 我发现此示例部分显示了我正在寻找的内容: http : //supportforums.blackberry.com/t5/Java-Development/Allow-a-background-listener-to-detect-and-update-a-GUI / ta-p / 442907一个问题是,我在模拟器中执行此操作,但我不知道如何执行此代码,因此我无法真正调试其工作方式。 I've been told that keylistener cant function in the background, which is unfortunate becuase its the easiest to test with. 有人告诉我,侦听器无法在后台运行,这是不幸的,因为它最容易测试。 What other listeners could i setup in this same fashion to easily test and learn how the code is working in the simulator? 我可以以同样的方式设置其他哪些侦听器来轻松测试和了解代码在模拟器中的工作方式?

Thanks! 谢谢!
Stephanie 斯蒂芬妮

除非您的应用程序的前景为屏幕,否则您不能收听键盘,轨迹球或触控板的输入。

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

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