Avatar Jonathan H Fisher - Blog - email: - Mobile: (uk) 07983607452

Too many threads error, HeaderField/Timers

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(){
headerTimer.cancel();
}

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.

No Comments, Comment or Ping

Reply to “Too many threads error, HeaderField/Timers”

Links

Technology:

Manchester:

Music:

Friends: