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
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810
Accepted Solution

pushScreen simple ?

Hi all.

 

I am developing for BB for some time and have not had the need to use Dialog(s) up until now.

 

And now I am in a bit of embarrassing situation, because I cannot seem to get a simple pushScreen to work

 

This is what I do:

 

public class someClass {

private UiApplication application;

 

public someClass (UiApplication application)
{
this.application = application;
}

 

public someMethod ()

{

synchronized(UiApplication.getEventLock())
{
try
{
application.pushScreen(settingsScreen);
//application.pushGlobalScreen(settingsScreen, 4, UiEngine.GLOBAL_SHOW_LOWER);
}
catch (Exception e)
{
throw new RuntimeException("FAILED to push settingsScreen");
}
}

}

 

After calling someMethod() the first time, nothing is displayed.

Then I call it the second time and I get the exception:

"Attempt to push Screen while already displayed!"

 

The exception would be ok if something actually was shown on the screen but, it isn't.

 

 What have I missed ?

P.S. But if I use the commented out pushGlobalScreen() the screen is shown. But the problem is that any later on (save on close, fro instance) dialogs don't get shown.

 



"Listen carefully, I shall say this only once"
Please use plain text.
New Developer
neek2000
Posts: 9
Registered: ‎11-12-2008
My Device: Not Specified

Re: pushScreen simple ?

[ Edited ]

Here is my Code, it works well

 

 

protected void popupScreen(Screen screen){

synchronized (UiApplication.getEventLock()) {

UiApplication.getUiApplication().pushScreen(screen);

}

}

 

 

Message Edited by neek2000 on 11-17-2008 06:08 AM
Message Edited by neek2000 on 11-17-2008 06:09 AM
Please use plain text.
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: pushScreen simple ?

Thx, but

what is the difference ?

why does pushGlobal work and push Screen doesn't ?



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
simon_hain
Posts: 16,209
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: pushScreen simple ?

the error message should help you: "trying to push a screen that is already displayed"
my first guess would be that you do not pop your settings screen but leave it on the display stack.
----------------------------------------------------------
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
Please use plain text.
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: pushScreen simple ?

Yes, well I put that exception here just to show that the screen does get pushed on stack, but it is never displayed.

 

I am trying to grasp that whole 'push screen' thing.

 

I cannot seem to find a single source that explains pushGlobalScreen().

I am currently testing all of its priority(2)/UiEngine.GLOBAL_XXX(3) combinations.

 

But the problem is that my underlying screen is also pushed using pushGlobalScreen so I have (2*3)*(2*3) combinations to test out :smileyhappy: to fully understand how it works.



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
simon_hain
Posts: 16,209
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: pushScreen simple ?

see the API:
Adds a screen to the queue of displayed global status screens. Global status screens appear on top of all other screens on the device, even if the current application is not in the foreground

flags:
GLOBAL_MODAL -- block until the screen closes
GLOBAL_QUEUE -- insert the screen underneath global screens of equal priority
GLOBAL_SHOW_LOWER -- don't suppress the display of global screens with lower priority

if you have to use global screens
- if you have an UiApplication you normally don't use them. and as you are not allowed to "overwrite" stuff like the incoming call screen on a real device: why do you need them? -
i guess you have to use GLOBAL_SHOW_LOWER with each of them and adjust the priority accordingly to show them in the correct order (i didn't try this).

in most cases a simple pushScreen is sufficient, the display is a normal LIFO stack and should be easier to handle.
----------------------------------------------------------
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
Please use plain text.
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: pushScreen simple ?

Yes, I've already gone through the API, but am porbably missing something important (oh, Murphy).

 

The above mentioned class that want's to display an Alert dialog is a part of a larger system and it only has a reference to the main UiApplication. But the display time of that some other screens is determined by a dispatcher thread (unrelated to any UiApplication).

 

In that thread I pushGlobalScreen (because I cannot use pushScreen from it) with  GLOBAL_SHOW_LOWER.

 

Later on that screen should (again activated from a dispatcher thread) popup an Alert dialog.

 

this code is fine:

 

UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
fSaveDialog = new Dialog("Save changes?",
new String[]
{
"Save", "No"
},
new int[]
{
Dialog.SAVE, Dialog.NO
},
Dialog.SAVE,
Bitmap.getPredefinedBitmap(Bitmap.QUESTION));

fSaveDialog.setDialogClosedListener(new DialogClosedListener()
{
public void dialogClosed(Dialog aTheDialog,
int aDialogReturnValue)
{
if (aDialogReturnValue == Dialog.SAVE)
{
saveBranch();
}
}
});

UiApplication.getUiApplication().pushGlobalScreen(fSaveDialog, 100, UiApplication.GLOBAL_MODAL);
}

}
});

}

(sorry if I've dropped a bracket or two)

But the problem is that the popup is sometimes shown only after i close the 'caller' screen. Or (in another case -GLOBAL_MODAL for the Alert dialog) the dialog gets pushed to the top of the stack but is shown on a bb main screen !?

 

So, I am continuing my tests.

 

 

 



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
simon_hain
Posts: 16,209
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: pushScreen simple ?

you can try to use UiEngine instead of UiApplication if it is called from the background thread (as this thread does not have its own ui engine, or, if running as a listener, the one from its master-application):

Ui.getUiEngine().pushGlobalScreen(dialog, 1, UiEngine.GLOBAL_QUEUE);

If your background thread changes the status of your application (or the pushed screen does) it may be better to notify the application instead of doing the Ui stuff on its own.

for example (some different solutions):
- http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To_...
- use application manager to call an alternative entry point
- use global events (if your main app is already running)

----------------------------------------------------------
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
Please use plain text.
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: pushScreen simple ?

This link is very useful.

 

Thanks for the help !



"Listen carefully, I shall say this only once"
Please use plain text.
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: pushScreen simple ?

Actually,

 

the fact that you can combine flags did the trick:

 

UiApplication.GLOBAL_SHOW_LOWER | UiApplication.GLOBAL_MODAL

 

(first part said: show anything that is behidn this screen)

(second part said: pout me on top and wait until I close)

 

Thanks for the help !



"Listen carefully, I shall say this only once"
Please use plain text.