PopupScreen not show after pushing - blackberry

I push the pop screen using following code, what pop screen not displays.
Please tell me what I missed.?
LabelField statusMsg = new LabelField("Hello");
PopupScreen statusScreen = new PopupScreen((fieldHFM));
UiApplication app = UiApplication.getUiApplication();
app.pushScreen(statusScreen);

Try
to do in following way
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(statusScreen);
}
});

Related

Blackberry splash screen wait issue

I'm trying to launch a splash screen for a few seconds and then close it and launch the second screen.
For some reason, the code executes the "sleep" before showing the splash page and the splash page appears only for a fraction of a second and the second screen appears immediately. In other words when I click on the app icon, it waits for 2 seconds, then shows and immediately hides splash and jumps to HomeScreen.
I've tried many different combinations including invokeAndWait(), call backs and threads inside the Splash class but to no avail.
I've gone through many posts on SO as well.
Please note that I do not want the splash page to open the next screen; the launcher of the splash page (AppStart) should launch the next screen.
Please suggest a solution.
Code:
public class AppStart extends UiApplication
{
public static void main(String[] args) {
AppStart app = new AppStart();
app.enterEventDispatcher();
}
public AppStart() {
final Splash splashscreen = new Splash();
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(splashscreen);
}
});
Thread waitthread = new Thread()
{
public void run()
{
try {
sleep(2000);
} catch (InterruptedException e) {
}
finally
{
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(splashscreen);
}
});
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(new HomeScreen());
}
});
}
}
};
waitthread.run();
}
}
Splash
public class Splash extends MainScreen {
public Splash()
{
Bitmap bgImg = Bitmap.getBitmapResource("480x320-SplashScreen.png");
Background bg = BackgroundFactory.createBitmapBackground(bgImg);
getMainManager().setBackground(bg);
}
}
waitthread.run();
That is the problem. You are not starting a new thread, but hogging the main thread instead by callyng a method that sleeps it. Replace that line with this one:
waitthread.start();
And it should work.

BrowserField not showing the website.

This is the code i m running in my blackberry bold 9900 simulator but the BrowserField just shows the blank white screen and nothing. Is there any problem with my simulator or some setting needs to be done in it. Thanks in advance for help.
public class StartUp extends UiApplication
{
public static void main(String[])
{
StartUp start=new StartUp();
start.enterEventDispatcher();
}
public StartUp()
{
MainScreen screen = new MainScreen();
BrowserField browserField = new BrowserField();;
screen.add(browserField);
pushScreen(screen);
browserField.requestContent("http://www.google.com/news");
}
}
Verify if you have a network connection in your simulator, see this development guide article.

PopUpScreen Blocking events in Blackberry

I am using a popup screen to show the update status of background uploading processes. I want to cancel the uploading in between. I am trying to achieve this either by addin a button to the pop up screen or with the physical backbutton of the device. But it seems that none of the events generated are caught by the app.
Here is how I am creating a popup screen and displaying it t user
DialogFieldManager manager = new DialogFieldManager();
//DialogFieldManager manager = (DialogFieldManager)getDelegate();
statusUpdate = new LabelField("Please Wait...");
manager.addCustomField(statusUpdate);
_gaugeField = new GaugeField("", 0, 100, 0, GaugeField.PERCENT);
manager.addCustomField(_gaugeField);
cncl_Btn = new ButtonField("Cancel",ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER | ButtonField.NEVER_DIRTY);
manager.addCustomField(cncl_Btn);
cancelFlag = 0;
cncl_Btn.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context) {
// Auto-generated method stub
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
cancelFlag = 1;
//onClose();//as this method exited from application
// close();//this method gave me IllegalStateException
}
});
}
});
//BackUpScreen.this.addMenuItem(_viewItem);
popup = new PopupScreen(manager);
UiApplication.getUiApplication().pushScreen(popup);
Soon afther this line I am calling the actual upload process in a thread like this
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
//.... do other stuff I wanted done...
backUpThread = Thread.currentThread();
uploadItems();
}
});
But if I press the cancel button inside the popup screen its not responding. I checked this by adding a breakpoint inside the fieldchange listener method of button.
How can I do this in blackberry?
The call to invokeLater (int the second bit of code) causes that Runnable to be executed on the event thread. If anything you do on the event thread blocks then the UI will become unresponsive as you describe. Any calls that may block must not be run on the event thread.

Blackberry splash screen delay before appears

I need to display a splash screen when I app instantiate, I wrote a class for splashScreen based on blackberry develpers knowlwdebase (link).
And its invoked from my following class.My problem is the splashscreen appears only after a deley,How can I solve it,If any one have idea Please help me,Thanks
class Test extends MainScreen{
Test(){
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run() {
UiApplication app=(UiApplication)getApplication();
Bitmap image = Bitmap.getBitmapResource("splah.png");
ListView listView = new ListView();
new SplashScreen(app, listView );
}
}
Try synchronized (UiApplication.getEventLock()). It is faster than invokeLater.
Test(){
synchronized (UiApplication.getEventLock()) {
UiApplication app=(UiApplication)getApplication();
Bitmap image = Bitmap.getBitmapResource("splah.png");
ListView listView = new ListView();
new SplashScreen(app, listView );
}
}

Navigate one screen to another screen based on time period in BlackBerry app

For my Blackberry application I am using a start up screen with progress bar. I am filling the progress bar using a timer and after the progress bar is complete, I need to navigate to another screen.
I am checking like this, where 'i' is time, increasing from 0 to 100.
timer.cancel();
if(i>=99)
UiApplication.getUiApplication().pushScreen(new TipCalculatorScreen());
This code is not working.
For progress bar I am using code like this:
private GaugeField percentGauge;
percentGauge = new GaugeField(null, 0, 100,50, GaugeField.PERCENT);
timer=new Timer();
timer.scheduleAtFixedRate(new TimerTask(){
int i=0;
public void run() {
percentGauge.setValue(i);
i++;
if(i>=99)
{
timer.cancel();
//for page navigating i am given like this here screen is not navigating getting error
UiApplication.getUiApplication().pushScreen(new nextscreen());
}
}
}, 100,100);
You need to make changes to the UI on the UI thread. The TimerTask is executing on its own thread. Instead of
UiApplication.getUiApplication().pushScreen(new nextscreen());
you should use
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication()..pushScreen(new nextscreen());
}
});
The update to your gauge control probably needs the same treatment.

Resources