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: 88
Registered: ‎11-04-2008
My Device: Not Specified

IllegalArgumentException in popScreen()

public void displayScreen2() { Screen screen = myApp.getActiveScreen(); // Gets the active screen if(screen instanceof Screen2) // if active screen is Screen2 { myApp.requestForeground(); // bring application to the foreground } else { UiApplication.getUiApplication().popScreen(screen); // Pop the active screen Screen2 screen2 = myApp.getScreen2(); // Get the Screen2 from the application UiApplication.getUiApplication().pushScreen(screen2); // push Screen2 myApp.requestForeground(); // bring application to the foreground } }

 

Here is the situation.

 

myApp is currently running in the background (c/o requestBackground()).

I have an application menu item added in the Email List.

 

Correct Scenario:
ApplicationMenuItem -> call displayScreen2()

 

Incorrect Scenario:
ApplicationMenuItem -> Push a Global Screen -> from the Global Screen, call displayScreen2

 

In the Incorrect Scenario, i get an IllegalArgumentException. When i debugged it, i found out it was due to the popScreen method in the else block. IllegalArgumentException is thrown when i try to pop a screen that is not in the stack, right? But i am only popping the active screen which was returned by my application and i checked its contents, the activeScreen is not null. It is the right screen that i want to pop.

 

So why am i getting an IllegalArgumentException? is this maybe due to the GlobalScreen?

Developer
Posts: 38
Registered: ‎02-04-2009
My Device: 9530

Re: IllegalArgumentException in popScreen()

try using UiApplication.getUiApplication().getActiveScreen()

 

any difference?

New Developer
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Re: IllegalArgumentException in popScreen()

I tried that, but it gives me the current active screen which is the, in this example, Email List.

I want to get the active screen of my application that is running in the background. That is why i am using myApp.getActiveScreen().

 

Also, i tried both conditions, without the GlobalScreen part, it works just fine.

 

I'm starting to conclude that it could be because of the Global Screen. But i'm just not sure.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: IllegalArgumentException in popScreen()

If this code is being called from an ApplicaitonMenuItem, then the thread bing used to push the screen is not your event thread - it is the thread of the calling application.

 

The UI is non re-entrant and can only be called by:

 

a) the event thread

b) by placing the UI cod ein a Runnable object and using UiApplication.invokeLater() to execute it

c) by synhronizing on the event lock

 

 

New Developer
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Re: IllegalArgumentException in popScreen()

[ Edited ]

Here is more information about the Exception that occurred:

popScreen: UiEngine is net.rim.device.api.ui.UiEngineImpl@319ae404 != net.rim.device.api.ui.UiEngineImpl@54879ee9

Message Edited by jacytan on 07-16-2009 03:59 AM
New Developer
Posts: 88
Registered: ‎11-04-2008
My Device: Not Specified

Re: IllegalArgumentException in popScreen()

i tested the code in two different application menu items.

 

First application menu item:

Location: Message List

Scenario: When run() method invokes UiApplication.getUiApplication, the return is MessageListUI.

 

Second application menu item:

Location: File Explorer

Scenario: When run() method invokes UiApplication.getUiApplication, the return is myApp.

 

Why do they have different results? I want the first application menu item to have the exact behavior of the second application menu item.

 

Can somebody help me?

Highlighted
BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: IllegalArgumentException in popScreen()

UiApplication.getUiApplication returns a UiApplication instance for the current process.  The run method of an ApplicationMenuItems could run in the process for another application.

 

You can store a singleton reference to your application in the RuntimeStore that you could reference within the ApplicationMenuItem.  Please refer to the following examples.

 

How to - Create a singleton using the RuntimeStore
Article Number: DB-00686

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/832062/How_to_...

 

How To - Allow a background listener to detect and update a GUI application
Article Number: DB-00406

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To_...

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