开发者

BlackBerry - Does TimerTask run in the background?

Does TimerTask work even if my exit my application and come to home screen or explore other apps? I have read the forum and find out the thread kind of easy mechanism is to use TimerTask in BB. I want to have thread running always even my app is not launched(after first time), so that when an particular interval arrives, i can show my dialog from application. I tried t开发者_StackOverflow中文版he below: (i am having this code, not in MainScreenClass instead first push screen class)

 try {
  timer = new Timer();
  // start after 1 second, repeat every 5 second
  // timer.schedule(new ClickTask(), 0, 5000); // seconds*1000
  timer.scheduleAtFixedRate(new ClickTask(), 0, 5000);
 } catch (Exception e) {
  // do nothing
 }

 private class ClickTask extends TimerTask {
  public void run() {
   System.out.println("Test Printing..");
   // Screen screen = new Dialog(Dialog.D_OK, 
   // "Look out!!!", Dialog.OK,
   // Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),
   // Manager.VERTICAL_SCROLL);
  }
 }

But it does running the timer only when my application is launched. If i quit from my application and come to device home screen, seems to be log is not printing(i.e. timer is not running). Is my code right? Is this the way to run timer in the background as thread? Note: I'm testing on 9530 Simulator for this.

Thanks for your helps.


TimerTask is for when your application is actually running.

Look at PushRegistry.registerAlarm() for launching your application after an interval.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜