Code:
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?