BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-28-2009, 05:24 PM   #1 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Alltel
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default View refresh pattern please

Please Login to Remove!

Hello

I have an app that syncs its data model in a separate thread.

I have a refresh method in my MainScreen that updates the view of the model.

If I add a menu item that invokes the refresh method, it works just fine. But, I'd like to just periodically update the view, maybe in a TimerTask. When I try this, I get an illegal state exception.

I'm interested in common patterns for what I'm trying to do and maybe a code snippet that would help or a pointer to a sample project that does this.

Thanks
Offline  
Old 01-28-2009, 08:11 PM   #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

I assume that you are basically implementing the Observer pattern in your Model class?

Since the Model is not running in the main event thread, then any attempt to update UI components from the Listener method (in the View class) will result in an exception. you need to encapsulate the required UI update in a Runnable class, and use UiApplication.invokeLater() to queue the command so that it executes in the main UI enent thread.

See the API docs for Runnable and UiApplication.invokeLater().
Offline  
Old 01-28-2009, 10:27 PM   #3 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Alltel
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excellent. Thanks!

To help others, here is essentially what I've done.

In my application's ctor, I create the model, create the view/controller (which is essentially the main screen), then I call invokeLater() on my RefreshRunnable (just an implementation of Runnable) which calls a refresh function in my view every 5 seconds.

This all happens before enterEventDispatcher() is called in the app's main().

Thanks!
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

Trimpot Potentiometer 100K Ohm Bourns 3310 9mm Square 3310Y-PK8-104L 50pcs
$29.97
Trimpot Potentiometer 100K Ohm Bourns 3310 9mm Square 3310Y-PK8-104L 50pcs pictureNew Allen Bradley JA1N056S104UA Potentiometer JA1N Type 25526
$3.99
New Allen Bradley JA1N056S104UA Potentiometer JA1N Type 25526 picture10cps Potentiometer Knob Inner 6mm External 15mm High 17mm Hot
$0.99
10cps Potentiometer Knob Inner 6mm External 15mm High 17mm Hot picture10 pcs Used Potentiometers Various Values
$3.69
10 pcs Used Potentiometers Various Values picture1ab 20-Qty LOT ALLEN-BRADLEY 1-MEG RECT CERMET SEALED Potentiometer Variable
$0.99
1ab  20-Qty LOT ALLEN-BRADLEY 1-MEG RECT CERMET SEALED  Potentiometer Variable picture






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