Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Developer
Posts: 40
Registered: ‎12-28-2011
My Device: Torch 9800
My Carrier: AT & T
Accepted Solution

Is Screen.invalidate() inside a TimerTask possible?

My goal is to update the screen of my app every minute. Inside my screen class I've attached a bitmapfield class with override paint() method, and also a timer and timer task. I want the bitmapfield's paint method be called every minute by screen.invalidate() I put inside my TimerTask's run() function. Would this be possible or should I try other methods?t
Regular Contributor
Posts: 66
Registered: ‎06-12-2010
My Device: 8300-Curve
My Carrier: Airtel

Re: Is Screen.invalidate() inside a TimerTask possible?

It's very much possible but make sure you have a hold on the timer

 

      TimerTask timerTask = new TimerTask()
      {
             public void run()

              {

                   invalidate();
              }
      };
      timer.scheduleAtFixedRate(timerTask, ANIM_DELAY, ANIM_PERIOD);

 

Regards,

Abhijit B

New Developer
Posts: 40
Registered: ‎12-28-2011
My Device: Torch 9800
My Carrier: AT & T

Re: Is Screen.invalidate() inside a TimerTask possible?

Thank you for the prompt response and your suggestion about Timer. That reminds me, previously I used timer.schedule() not realizing it will only execute once, where as scheduleAtFixedRate will repeat.
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: Is Screen.invalidate() inside a TimerTask possible?

Main Screen{

:

:

StartTimer();
}

void StartTimer() {
timer = new Timer();
//1000=1second delay will cause unknown source error.
timer.schedule(new TimerTick(), 20000, 2000);
}

private class TimerTick extends TimerTask {

public void run() {

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
try {
butstop();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

});
}
}

-Fight with BB10