07-14-2009 03:31 AM
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(screen 2); // 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?
07-14-2009 04:10 AM
try using UiApplication.getUiApplication().getActiveScreen()
any difference?
07-14-2009 06:58 AM
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.
07-14-2009 08:31 AM
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
07-16-2009 03:55 AM - edited 07-16-2009 03:59 AM
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
07-20-2009 02:06 AM
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?
07-22-2009 02:05 PM
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
How To - Allow a background listener to detect and update a GUI application
Article Number: DB-00406