BlackBerry Forums Support Community

Closed Thread
Thread Tools
Old 12-07-2007, 01:57 PM   #1
New Member
Join Date: May 2007
Model: 7100
Carrier: Airtel
Posts: 12
Default pushScreen on thread closing

Please Login to Remove!

Hi all,
My application runs a thread to make an HTTP connection and fetch data. I want to push next screen on the termination of this thread indicating that the data has been downloaded. How can I do this?
I tried doing pushScreen in the onClose() method of the thread, but nothing happened. On debugging, I found, the application crashes with UncaughtException with no details. Please let me know where am I going wrong.

Thanks and regards,
Old 12-08-2007, 01:46 AM   #2
Talking BlackBerry Encyclopedia
richard.puckett's Avatar
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
Carrier: T-Mobile
Posts: 212

What do you mean by "the onClose() method of the thread"?

You really should look at some kind of publish/subscribe (Observer) architecture for this kind of stuff; you don't want to bind up all your code so it can never be reused.

For now though, try something like:

Application.getApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication.pushScreen(new MyScreen());
Old 12-13-2007, 02:15 PM   #3
Mark Rejhon
Retired BBF Moderator
Mark Rejhon's Avatar
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870

richard.puckett is right.

This is a better coding architecture: push the screen; when it closes, have the original class that pushed the screen display the final screen.

This is an okay coding architecture (better than what you do), push the confirm screen then immediately push the loading screen. There will be no time for the confirm screen to repaint itself. Once the loading screen closes, the confirm screen shows. (This doesn't show error messages, etc, but at least it's much more modular and easier to convert to an even better coding architecture)

Other comments about having two screens communicate with each other:
There are many ways of signalling a previous screen of a task completion, such as a callback, a semaphore, etc. Some even passing the screen as a variable to the new screen, so that the new screen can call a function within the original screen. An example is pass the original screen to the loading screen as a "Screen origScreen" parameter, then check that Screen is "if (origScreen instanceof MySpecificScreenClass)" and if it is, then you can safely call your own custom functions in your original MySpecificClass screen, through a construct similiar to ((MySpecificClass) origScreen).myOwnFinishedLoadingFunc( ) .... (you may have to cast to a variable first, before calling the method) It works. Be forewarned of potential caveats of any approach you do, and try to program as generically as possible that your situation allows. It's a very powerful BlackBerry programming trick: It's very tempting to do this trick to do neat things such as modify the textfields of a previous screen while the next screen is still displayed (Not good programming practice, as this is only appropriate to do, if the two screens are intricately related to each other and are never used by itself anywhere else, and that other programming techniques may be more difficult. You'd need a very good reason to do things this way - I prefer doing a callback returning a populated object and let the previous screen populate fields on its own, it's a lot more generic/blackbox this way -- i.e. like a 411 popup lookup screen that populates fields in the previous screen)
Mark Rejhon
Author of XMPP extension XEP-0301: - specification - open source

Last edited by Mark Rejhon; 12-13-2007 at 02:26 PM..
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

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

Forum Jump

Allen-Bradley 1747-L532 /D SLC 500 SLC 5/03 CPU Frn 9 *READ*
Allen-Bradley 1747-L532 /D SLC 500 SLC 5/03 CPU Frn 9 *READ* pictureGE General Electric 531X309SPCAJG1 F31X309SPACJG1 Single Processor OPEN BOX
GE General Electric 531X309SPCAJG1 F31X309SPACJG1 Single Processor OPEN BOX pictureOMRON CQM1H-CPU51
OMRON CQM1H-CPU51 pictureAutomation Direct D2-250-1 CPU Module
Automation Direct D2-250-1 CPU Module pictureAllen Bradley 1747-L541 /B SLC 500 SLC 5/04 CPU Processor Unit Frn 7 *READ*
Allen Bradley 1747-L541 /B SLC 500 SLC 5/04 CPU Processor Unit Frn 7 *READ* picture

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