BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-28-2009, 05:24 PM   #1
jrlawhorne
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Alltel
Posts: 12
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
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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
jrlawhorne
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: Alltel
Posts: 12
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



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


Vintage Apple Computer 4” Paper Cube Notepad Macintosh 80s 90s Office White picture

Vintage Apple Computer 4” Paper Cube Notepad Macintosh 80s 90s Office White

$39.95



6502 CPU - Over 100 chips on a vintage 4 inch Silicon wafer picture

6502 CPU - Over 100 chips on a vintage 4 inch Silicon wafer

$275.00



Apple 1 Replica IC's: Vintage IC’s Many Types See List NOS 74XXX Types - Apple I picture

Apple 1 Replica IC's: Vintage IC’s Many Types See List NOS 74XXX Types - Apple I

$20.00



Vintage Post-it Note Pad Apple Magnetic Holder Pince A Notes Unused 1988 NOS picture

Vintage Post-it Note Pad Apple Magnetic Holder Pince A Notes Unused 1988 NOS

$16.99



Lot of 6 Vintage Apple Drawstring Bags For iPhone, Mac, Apple Watch, iPod picture

Lot of 6 Vintage Apple Drawstring Bags For iPhone, Mac, Apple Watch, iPod

$45.00



Retro 1951 Apple Computer Logo 0.7mm Ballpoint Black Ink Pen Gold Barrel picture

Retro 1951 Apple Computer Logo 0.7mm Ballpoint Black Ink Pen Gold Barrel

$56.41







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