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()
开发者_如何学Go {
}
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!
StephanieYou can't listen for keypad, trackball or trackpad input unless your application has a screen in the foreground.
精彩评论