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
New Developer
Posts: 18
Registered: ‎09-18-2008
My Device: Not Specified

Remove Popup

I found this class to show a popup screen whilst my app performs some tasks.  I can invoke the popup screen fine but can't get rid of it.  How should I be calling the remove method?

 

UiApplication.getUiApplication().invokeLater( new Runnable()
         {
             public void run ()
             {
              ProgressBar Progress = new ProgressBar("My Message", 100, 100);
              Progress.run();
              
                           }
         } ); 

 

  

/**
* Defines ProgressBar object. Creates popup screen with title, and perpetually updating
* progress gauge. Instantiate and run as thread to start progress update. Call
* remove() method when finished to remove popup screen and shutdown thread.
*/
package me.com

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.GaugeField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.DialogFieldManager;
import net.rim.device.api.ui.container.PopupScreen;

public class ProgressBar extends Thread {

private int maximum, timeout;

private boolean useful;

private PopupScreen popup;

private GaugeField gaugeField;

/**
* Object constructor
*
* @param title
*           Text to display on popup area
* @param maximum
*           Range / width of the gauge field of progress bar
* @param timeout
*           Milliseconds to pause between updates to progress bar
* @see GaugeField
* @see Thread
* @see PopupScreen
*/

public ProgressBar(String title, int maximum, int timeout) {
this.maximum = maximum;
this.timeout = timeout;

DialogFieldManager manager = new DialogFieldManager();

popup = new PopupScreen(manager);
gaugeField = new GaugeField(null, 1, maximum, 1, GaugeField.NO_TEXT);

manager.addCustomField(new LabelField(title));
manager.addCustomField(gaugeField);
}

/**
* run() method for starting thread
*/

public void run() {
useful = true;

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(popup);
}
});

int iterations = 0;

while (useful) {
try {
Thread.sleep(timeout);
} catch (Exception e) {
}

if (++iterations > maximum)
iterations = 1;

gaugeField.setValue(iterations);
}

if (popup.isDisplayed()) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(popup);
}
});
}
}

/**
* Method to shutdown the thread and remove the popup screen

*/

public synchronized void remove() {
useful = false;
}
}

 

BlackBerry Development Advisor
Posts: 15,117
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Remove Popup

One problem here is that you are calling Progress.run instead of Progress.start. 

 

Calling run will just execute the run method in your current thread (blocking that thread at that line).  This is also blocking the main event thread, which means the application won't respond to any key presses.

 

Calling start will cause the run method to execute in your new thread.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Remove Popup

...and the other problem is that you are not maintaining a reference to the screen so that you can pop it when you are ready to.

 

Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry

Re: Remove Popup

Hi am using this code but popscreen is not shown. Why its not working?

Developer
Posts: 19,628
Registered: ‎07-14-2008
My Device: Not Specified

Re: Remove Popup

Have you stepped through the code in the debugger?  Which line does it get to?