黑莓后台监听线程 [英] Blackberry background listener thread

查看:371
本文介绍了黑莓后台监听线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我是新黑莓编程,虽然我也有部分的java的经验,用C#是我的主要语言)。

Hey everyone! I am new to blackberry programming although I do have some java experience, with c# being my main language).

我所试图做的是编写将在系统启动时运行,并在后台侦听器存在一个线程。

What I am trying to do is write a thread that will run on system startup and exist in the background as a listener.

我想我的应用程序来实现的KeyListener,基本上坐在后台,而手机处于开机状态,并跟踪有多少次,每次按钮已被pressed直方图。我目前在模拟器上运行了,现在我只是把它打印到控制台当它到达一个关键的左右。

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

我已经能够实现在一个的UIApplication但KeyListener的而应用程序加载它仅适用。

I have been able to implement a keyListener in a UIApplication but it only works while the app is loaded.

下面是我当前的应用程序

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
    }

这只有在应用程序是开放的,虽然工作。所以它不是真的我想要实现的。如果任何人都可以在正确的方向指向我,我会把AP preciate吧!

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!

编辑:

我发现这个例子,显示部分就是我在寻找:<一href=\"http://supportforums.blackberry.com/t5/Java-Development/Allow-a-background-listener-to-detect-and-update-a-GUI/ta-p/442907\" rel=\"nofollow\">http://supportforums.blackberry.com/t5/Java-Development/Allow-a-background-listener-to-detect-and-update-a-GUI/ta-p/442907
一个问题是,即时通讯在模拟器这样做的,我不知道如何行使这一code,这样我可以通过它如何工作真的调试。有人告诉我在背景的KeyListener着的功能,这是不幸的监守其最简单的来测试。还有什么其他的听众我能安装在这同样的方式轻松测试,并学习如何在code在模拟器工作?

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

推荐答案

您不能听<一个href=\"http://supportforums.blackberry.com/t5/Java-Development/add-a-keyListener-to-BlackBerry-email-client/m-p/29559#M2109\"相对=nofollow>键盘,轨迹球或触控板输入,除非你的应用程序在前台的屏幕。

You can't listen for keypad, trackball or trackpad input unless your application has a screen in the foreground.

这篇关于黑莓后台监听线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆