Blackberry background listener thread

三世轮回 提交于 2020-01-17 04:51:06

问题


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.

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.

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
    }

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


回答1:


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



来源:https://stackoverflow.com/questions/4661509/blackberry-background-listener-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!