BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-14-2009, 02:34 AM   #1
jacytan
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
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
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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
jacytan
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
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
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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
jacytan
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
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
jacytan
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Globe
Posts: 52
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


4.5 CFM Single-Stage Rotary Vacuum Pump HVAC/Auto AC 4.5CFM 1/3HP 1/4

4.5 CFM Single-Stage Rotary Vacuum Pump HVAC/Auto AC 4.5CFM 1/3HP 1/4"ACME inlet

$29.39



VEVOR 9

VEVOR 9" Drywall Sander 850W Vacuum System Folding 6 Speed LED Strip Light

$87.99



BISSELL PowerForce Helix Turbo Pet Upright Vacuum 3332 picture

BISSELL PowerForce Helix Turbo Pet Upright Vacuum 3332

$54.00



3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit picture

3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit

$44.83



NEW Portable Heavy-Duty Suction Machine HIGH SUCTION VACUUM UNIT PUMP picture

NEW Portable Heavy-Duty Suction Machine HIGH SUCTION VACUUM UNIT PUMP

$139.99



Cordless Vacuum Cleaner Stick Handheld for Carpet Pet Hair & Wood Floor Bagless picture

Cordless Vacuum Cleaner Stick Handheld for Carpet Pet Hair & Wood Floor Bagless

$96.90







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