BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-14-2009, 02:34 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default IllegalArgumentException in popScreen()

Please Login to Remove!

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?
Offline  
Old 07-14-2009, 07:36 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

The UI is non re-entrant and can only be accessed from within your own event thread, which is not what you are doing here if the code is called by the menu item callback.

See the answer in you duplicate RIM forum post.
Offline  
Old 07-14-2009, 08:21 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

There seems to be something wrong in the RIM forums. The link of my post is broken and when i try to search it, the thread doesn't exists.

Can you please post your answer here?
Offline  
Old 07-14-2009, 09:49 PM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

The RIM forum was apparently eaten by aliens (or something) today.

If your displayScreen2() is being called from a listener, then this is not YOUR event thread, right? Only YOUR event thread can access your UI, since the component is not re-entrant. If this is being called from ApplicationMenuItem, then the thread belongs to the calling app, not yours.

The typical way around this is to use UiApplication.invokeLater() to place the UI command in your own event thread. You would wrap your popscreen (or whatever) in a Runnable object, than pass this to invokeLater().

If you look around and search for invokeLater, you'll find dozens of similar issues.
Offline  
Old 07-16-2009, 02:58 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

I tried your invokeLater solution, still the exception persists.
Offline  
Old 07-20-2009, 01:08 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.