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

Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-, Z10 (STL100-3)-, Z30 (STA100-5)-, Passport (SQW100-1)-, PlayBook (16GB)-
My Carrier: Verizon

Re: Displaying the top banner in BlackBerry

For the clock, battery, network connection, etc. They aren't static, they change as time goes on.


You don't want to have a thread running when it's not visible but it keeps the timing going, what if you locked your BlackBerry and when you turned it on an hour later the time was the same because the thread stopped running when it wasn't visible?


The benefit of using a TimerTask is that all the timing and implementation are already there, on a Thread you would need to use the Thread.sleep function, determine how much time execution took, etc.


That should be easy for most but for some it is not easy enough, that's where TimerTask comes in.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: Displaying the top banner in BlackBerry

I think you missed the part of restarting the thread/timer task when the header becomes visible again Smiley Wink


The moment the device  goes out of back light off state, lock, etc the thread restarts.

Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Displaying the top banner in BlackBerry

Hi All,

The code provided by rcmania25 can be found here at




The "too many threads" issue was notified to the actual author and here is the fix the author provided




In case the link doesn't work here's the fix directly from the author:


I recently heard from a developer who was getting a ‘Too many threads’ exception when using the HeaderField custom field, it turned out the application was pushing and popping multiple screens and each time the timer object thread wasn’t cancelled which resulted in a cumulation of unused threads.

To overcome this issue in any field that uses a timer object implement the onUndisplay() method of the Field class which is invoked when the screen the field belongs to is popped from the display stack, for example in the HeaderField class add:

public void onUndisplay(){

from the javadoc:

    Terminates this timer, discarding any currently scheduled tasks. Does not interfere with a currently executing task (if it exists). Once a timer has been terminated, its execution thread terminates gracefully, and no more tasks may be scheduled on it.


All credit, respect and kudos to the creater of the HeaderBar Mr. Jonathan H. Fisher (contact@jonathanhfisher.co.uk)