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

Regular Contributor
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry

Timer to destroy application

Hello Everybody,

                          I am making an application in which I have made a "PleaseWait" screen during any transaction. I just want to make a timer on that screen,in which if it doesnot get any response from server than it will exit the application. Sample code for Response screen is given below:



public class PleaseWaitScreen extends PopupScreen
public PleaseWaitScreen()

super( new VerticalFieldManager());

this.add(new LabelField("Please Wait.....", LabelField.FIELD_HCENTER | DrawStyle.HCENTER));


public static void showScreenAndWait(final Runnable runThis) {
final PleaseWaitScreen thisScreen = new PleaseWaitScreen();
Thread threadToRun = new Thread() {
public void run()
// First, display this screen
UiApplication.getUiApplication().invokeLater(new Runnable() {

public void run() {
// Now run the code that must be executed in the Background
try {
catch (Throwable t) {
throw new RuntimeException("Exception detected while waiting: " + t.toString());
// Now dismiss this screen
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {


//Please kindly give me a response for this.

Thank You

Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Timer to destroy application

calling run does not launch a thread, it just executes the code. call start() instead.

use a callback to notify your application. you can use a timertask to do the timeout.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Timer to destroy application

This code appears to be from a sample I provided that is designed to be used to block the User interface when some background work is to be completed. 


You need to update the PleaseWaitScreen so that it displays the countdown and when the countdown is completed, cancels the application.  In fact this is not really related to the background processing at all. 


So rather than worry about the background processing, you can just think about how you would create a countdown in an ordinary screen.   Have a look at Timer and TimerTask, you can schedule a recurring event, then have the event display a countdown on the screen.  Once you have that working just add this code to the PleaseWaitScreen. 


I would suggest that you start this process and end the process in the onUiEngineAttached method.  If the attached flag is set, then you start the timer.  If not, then you can stop the timer because the screen has been popped off the stack - i.e. the background processing has completed. 


Hope this makes sense, ask if you need more.