BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-02-2008, 12:38 PM   #1
mrjimmy410
New Member
 
Join Date: Aug 2008
Model: sim
PIN: N/A
Carrier: sim
Posts: 4
Default Sample code for background operation?

Please Login to Remove!

New to BB dev and have some basics down, but need to solve this and am not looking to re-invent the wheel. Internet searches have not yielded a great answer here...

Use case.
1. User starts timer that updates UI stopwatch
2. User lets app sit idle or leaves app
a. timer keeps running
3. User returns to app and timer updates to correct time span

Ideas.
A. Figure out background thread operations; solve this way.
B. Fake it by persisting state when app closes or goes idle then regenerate state when app comes back(persist the time closed and diff against time re-opened...then continue if timer is still running);solve this way.

Thanks,
Jimmy

Using JDE 4.2.1
Offline  
Old 09-02-2008, 01:18 PM   #2
Dan East
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Default

First of all, you need to persist the time the stopwatch was started, instead of worrying about when your app was or wasn't running. Then the UI side of things is simply showing the difference between now and when the stopwatch started. If you're wanting to fire events (alarm clock, etc) then it's a different story, and you'll want to use some formal scheduling API.

One caveat - you should use some sort of standardized time for the timestamp, so timezone changes won't affect your difference calculation. The devices should switch timezones automatically for people that are traveling.
Offline  
Old 09-02-2008, 07:26 PM   #3
mrjimmy410
New Member
 
Join Date: Aug 2008
Model: sim
PIN: N/A
Carrier: sim
Posts: 4
Default

Thanks.

I seem to not be very efficient in using search because what I am looking for is a simple example that must exist.

1. User starts timer from menu item
2. UI starts counting
3. User lets app be idle (keeps counting in background)
4. User returns to app
5. UI keeps counting...

Basically this demonstrates updating the UI from a separate thread and dealing with idle apps. I am looking for best practices etc. so I do not re-invent the wheel.

Code sample anyone?
Offline  
Old 09-02-2008, 07:37 PM   #4
Dan East
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Default

Using a thread for that is overkill (not to mention that worker threads are limited in how they interact with the UI).

Just do something like this:
Code:
final Timer t=new Timer();
TimerTask tt=new TimerTask() {
    public void run() {
        //Set value of the field that displays the timer value here
    }
};

t.scheduleAtFixedRate(tt, 1000, 1000);
run will be called every second, so you just set the value you want displayed to whatever UI element you've created for that. Or you can call invalidate() within run, and have a paint routine that simply draws the current timer value (if you want to do the drawing yourself).

Last edited by Dan East; 09-02-2008 at 07:38 PM..
Offline  
Old 10-30-2008, 07:26 AM   #5
taqi.mir
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
Default

Hi,

In my application i want to set the number to generate the call automatically at a later time.
How we have got to do this?
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


ResQGARD Military Kit Impedance Threshold Device 12-0706-000 NSN 6515015758173 picture

ResQGARD Military Kit Impedance Threshold Device 12-0706-000 NSN 6515015758173

$25.00



LCR45 Atlas Passive Component Impedance Analyser (Model LCR45) PEAK ELECTRONICS picture

LCR45 Atlas Passive Component Impedance Analyser (Model LCR45) PEAK ELECTRONICS

$133.00



BECO Universal Impedance Bridge Model 315A, Brown Electro Measurement Corp. 315A picture

BECO Universal Impedance Bridge Model 315A, Brown Electro Measurement Corp. 315A

$139.00



TC ESI Impedance Bridge Model 250-DA Serial 1394 Electro-MeasurementS Oregon USA picture

TC ESI Impedance Bridge Model 250-DA Serial 1394 Electro-MeasurementS Oregon USA

$69.99



Digital Ohmmeter LCD Audio Impedance Test Meter Speaker Voice Resistor System picture

Digital Ohmmeter LCD Audio Impedance Test Meter Speaker Voice Resistor System

$56.99



BECO Universal Impedance Bridge Model 315A, Brown Electro Measurement Corp. 315A picture

BECO Universal Impedance Bridge Model 315A, Brown Electro Measurement Corp. 315A

$129.99







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