BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 12-07-2007, 01:57 PM   #1 (permalink)
New Member
Join Date: May 2007
Model: 7100
Carrier: Airtel
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Talking BlackBerry Encyclopedia
richard.puckett's Avatar
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts

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 (permalink)
Retired BBF Moderator
Mark Rejhon's Avatar
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts

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

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
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.