TimerTask

I have an application that I want to add a background process that needs to execute a task once per day. I studied with the help of another point of entry with a RealtimeClockListener and also just begin a TimerTask with a schedule fixed. Any advice? RealtimeClockListener is called each minute, so it seems best to use a TimerTask. If I leave a TimerTask to my main application and the farm of the app, is the TimerTask always configured to run? Do I have to reprogram the TimerTask at each reboot of the device even with a schedule fixed or the BB OS does that automatically? Operating of the TimerTask, is the UiApplication market too so that I can access it from within the TimerTask?

EDIT: Read further, seems that a timer is executed in a thread of the application, so I want another entry point again and put my TimerTask in there, correct?

Thank you

You can use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/ApplicationManager.html... long, boolean) to schedule an application to run at a specific time.

Tags: BlackBerry Developers

Similar Questions

  • TimerTasks battery drain!

    Hi gurus

    I am developing a project that has 2 main parts: the graphical interface and a background process. I do this with the help of another point of entry for the GUI. The background process starts automatically and the GUI is started using an application icon.

    What is the background process is 3 things:

    1. GPS location of the registry every 10 minutes
    2. Send GPS positions stored each hour to consume a web service (HttpConnection)
    3. Check if the user has saved records and send them to a server with the web services every hour.

    Sorry haven't looked hard to your code, but I see nothing that resets the LocationListener.  So I wonder if in fact the GPS is disabled?

    Memory, to stop a LocationListener, you need to do

    mLocProvider.setLocationListener (null, 1, 1, 1);

    I could be wrong, but I don't think that canceling the TimerTask will do that.

    I understand that there is advantage also made a getLocation() before departure using a LocationListener, to make sure that the GPS actually works.  But it would make your TimerTask blocking, and I'm not sure you want to do.

  • TimerTask calling UiApplication.getEventLock)

    I use a Timer object for several TimerTask objects that are run at various intervals (a few times per second, approximately every 30 seconds, etc, so nothing urgent). These objects TimerTask do very little work but they access various areas (e.g., setting the text of an EditField), and they call UiApplication.getEventLock () prior to do. And it works fine, no problem.

    However, in order to ensure I'm good things, because TimerTask or objects of a Timer object to follow very quickly, calling UiApplication.getEventLock () would be a problem, as it can effectively block thread of the Timer object, which is supposed to "finish quickly." Thank you

    The worst that will happen is that tasks planned for the future will be delayed in their execution. If your tasks are not urgent, then don't worry in this regard. In any case, nothing on the thread of the event is supposed to take long, either, so the wire from the timer should not have to wait a lot to synchronize the lock.

    If this is a concern, you can always use invokeLater rather than synchronize the lock of the event.

  • Problem of Timer and TimerTask for counter display all seconds on the screen.

    Dear friends,

    I have little problem in the use of the timer. I took the timer to display the counter on each period fix repeatedly. but I did not here. Please help me. The code is as shown below.

    import java.util.Timer.

    java.util.TimerTask to import;

    Import net.rim.device.api.ui.Field;

    Import net.rim.device.api.ui.UiApplication;

    Import net.rim.device.api.ui.component.RichTextField;

    Import net.rim.device.api.ui.container.MainScreen;

    SerializableAttribute public class TimerTest extends UiApplication

    {

    Timer;

    public static int COUNT = 0;

    Public Shared Sub main (String [] args) {}

    TimerTest tt = new TimerTest();

    tt.enterEventDispatcher ();

    }

    public TimerTest()

    {

    a new screen

    pushScreen (new TimerMainScreen());

    }

    SerializableAttribute public class TimerMainScreen extends screen

    {

    TimerMainScreen()

    {

    Add (new RichTextField ("Count =" + Integer.toString (COUNT), Field.NON_FOCUSABLE));

    try {}

    Timer = new Timer();

    timer.scheduleAtFixedRate (new TimerMainEvent (), 200, 1000);

    }

    catch (System.Exception e)

    {

    do nothing

    }

    }

    private class TimerMainEvent extends TimerTask

    {

    public void run()

    {

    Try

    {

    COUNT ++;

    If (COUNTY<>

    Add (new RichTextField ("Count =" + Integer.toString (COUNT), Field.NON_FOCUSABLE));

    on the other

    Timer.Cancel ();

    Timer.Cancel ();

    }

    catch (System.Exception e)

    {

    Do nothing

    }

    }

    }

    }

    }

    Please let me know where I'm wrong, I want to display all seconds on the screen. If I set the interval 0 then it run TimerMainScreen first time but after all no update, I see on the screen.

    I thank in advance

    Vimal

    Use the following Code in your race.

     UiApplication.getUiApplication().invokeLater(new Runnable()
     {
      public void run()
      {
       add(new RichTextField("Count = " + Integer.toString(COUNT)   ,Field.NON_FOCUSABLE));
      }
     });
    
  • IllegalStateException when adding label to the screen from timertask

    Hello

    I have a thread that gets the text for a labelfield. I just want to add the labelfield on-screen when the thread is finished.

    I have a timertask that checks when the thread is finished and when the thread is finished, he tries to add the label to the form.

    This is the code, but when I try to add the label I get illegalstateexception-

    GTC GetContent = new GetContent();
    t = new Thread (gtc);
    t.Start ();
                
    Timer = new Timer();
    timer.scheduleAtFixedRate (new TimerTask() {}
    public void run() {}
    {if (! t.IsAlive ())}
    Timer.Cancel ();
    Test string = t.getTextLabel ();
    addLabel (new LabelField (test));
    }
    }
    Invalidate();
    }
    (}, 1000, 1000);

    }
            
    Private Sub addLabel (LabelField l) {}
    Add (l);
    }

    If she runs in an external thread to wrap it in an invokelater (or the synchronization on the eventlock).

    You can check the exceptions by surrounding the code with a try/catch.

  • How can I restart a TimerTask, I want to reuse an instance of TimerTask on click of a button

    but I understand once you call it once that's all. That cannot be reused.

    I get everything I try and reuse the same instance of TimerTask errors of State invalid, surely there must be a way to restart?

    Hello

    public class TimersThread
    {
    Minu private;
    public TimersThread()
    {
    Timer = new Timer();
    Timer.Schedule (new TimerTask() {}
    public void run()
    {
    Synchronized (UiApplication.getEventLock ())
    {
    Timer.Cancel ();

    }
    }
    (}, 1000);
    }

  • Understanding, Timertask

    Hello

    I am trying to understand the process of timertask. After much research, I understand that I extend the timertask class and create a timer.

    In the run method, I wonder if I should paste my wireless network inside code or simply call the thread of the network of the run method.

    I'm also a few instansiate my class timertask or I should also call execution?

    Concerning

    Alex

    do not run the code blocking on a timertask.

    Call your wireless network of the run method.

    the run method is called by the Scheduler (timer).

  • How to get a TimerTask program itself?

    I'm trying to run a TimerTask to repeat at irregular intervals.

    that is when the TimerTask is running, it calculates the next interval, cancels, then attaches to the new interval.

    Like this:

    _runTimer = new TimerTask() {
        public void run() {
            _runTimer.cancel();
            int next = program[step];
            timer.schedule(_runTimer, next);
            step++;
        }
    };_runTimer.run()
    

    Except that it explodes with IllegalStateException on the row of the table.

    So if a TimerTask cannot plan itself, is there another model of how to do?

    Thank you

    If you want your TimerTask to run at irregular intervals, you can create a custom class that extends and create instances of it to the list.

    Timer timer = new Timer();
    
    private class RunTimer extends TimerTask {
       public void run() {
          int next = program[step];
          timer.schedule(new RunTimer(), next);
          step++;
       }
    }
    
    _runTimer = new RunTimer();
    
    timer.schedule( _runTimer(), program[step] );
    step++;
    
  • Pause a TimerTask - is there a reason for this?

    I use a TimerTask to update the screen of a meter. It updates all the few ms so it consumes a small amount of power. If the screen is not visible, it still sucks dry battery fast enough...

    Other than deleting and it rescheduling in every sense, is there a better model for a break it?

    What is the most effective approach to solve this type of problem?

    Thank you

    //////// Update Display Task
    _updateDisplay = new TimerTask() {
        public void run() {
            synchronized(MyApplication.getEventLock()) {
                timerRunning.setText(SWUtil.myFormat(countKeeper1.getTime()));
                timerCountdown.setText(SWUtil.myFormat(countKeeper1.getCountTime()));
            }
        }
    };
    _timer = new Timer();
    _timer.schedule(_updateDisplay, 25, 25);
    

    I see now. You must re-create the TimerTask every time. Is not supposed. Seems inefficient. But if that's what I have to do...

  • Screen.invalidate () is within a TimerTask possible?

    My goal is to update my application screen every minute. Inside the class of my screen, I joined a class bitmapfield with the substitution method of object, a timer and the timer task. I want the paint of the bitmapfield method be called every minute by screen.invalidate () I put inside my TimerTask run() function. This would be possible or should I try other methods? t

    It is entirely possible but make sure you have a hold the stopwatch

    TimerTask timerTask = new TimerTask()
    {
    public void run()

    {

    Invalidate();
    }
    };
    timer.scheduleAtFixedRate (timerTask, ANIM_DELAY, ANIM_PERIOD);

    Kind regards

    Abhijit B

  • Ugh... Requirement: A TimerTask making an HTTP call, parsing JSON, insertion into a SQLite database.

    How to implement a better design of the following?

    I have a UiApplication which has the following requirements:

    1. A static timer in the class that extends UiApplication.
    2. A class that extends screen and contains a class internal which extends TimerTask.
    3. When a user accesses to the screen, the TimerTask is started with:
      _timer.schedule(MyTimerTask, 1000, 15000);
      
    4. The first step is to do an HTTP call and return a valid JSON object which varies in structure - that is, it has a wide variety of paintings and JSON objects.
    5. The second step is to analyze and insert the JSON object values into tables in a SQLite database. The SQLite file is on the map.
    6. The third step is to read the updated SQLite table, loop through the table and build my ObjectListFields with the new values, and attach them to a VerticalFieldManager.
    7. The fourth step is to replace the old VerticalFieldManager with the new VerticalFieldManager and push the screen pop and updated then the current screen - so I have a stack of view high one single layer.

    Now the logic is actually on the spot, but since the TimerTask must cover every 15 seconds, I am a memory leak in all directions.

    To try to solve this problem, I have:

    • Cancelled the TimerTask with the onObscured and the onUiEngineAttached (false).
    • Restart the TimerTask with onExposed and onUiEngineAttached (true).
    • My DatabaseConnection closed the finally statement.

    However, when I look at the objects in Eclipse BlackBerry objects View when the TimerTask is not running, I still see 1 ~ 4 TimerTask objects and 1 ~ 4 DatabaseConnection objects.

    TimerTask both DatabaseConnection have a static instance (I don't have several entry points) with the following in my class that extends UiApplication:

    public static Timer _timer = new Timer();
    public static Database db = null;
    

    I attribute db when I need it with a call to DatabaseFactory.open within the class that extends TimerTask.

    Now that the business logic is correct, how to improve the design so I don't not leaking memory in every way?

    The statement closed the database is being called in, because I can set a breakpoint and see it has reached.

    Instead of onObscured/etc, you can move them into onVisibilityChange (boolean) is only in one place. Cancel your existing TimerTask before running a new, or at least check the TimerTask reference if you are only creating a... not just passing 'New TimerTask' in the calendar method without being able to track this object reference.

  • TimerTask vs Thread - what is a difference?

    I can achieve TimerTask with thread, but what will be different?

    Why should I use threads instead of TimerTask? Because in the 6.0.0.448 OS TimerTask does not, if it initialized in the Application class, no UiApplication.

    So, is there a difference for this solution? Is the sleep() function will drain the battery instead of TimerTask?

    My API documentation tells me that it is used every minute.  Check the text for clockUpdated.

    You add this listener using your Application.  Check the Application API.

  • How to check a timertask calendar is still active or not?

    Hello

    I created the following code:

    class StateTracker extends TimerTask
    {
    Minu private;
            
    public StateTracker()
    {
    Timer = new Timer();
    Timer.Schedule (this, 5000, 150000); begins after 5seconds Repeat task every 150 seconds
    }

    public void run()

    ....

    }

    The code runs allright, unless, in certain circumstances, the task stopped after a few periodic race (I suspect is disconnected network). Y at - there any API I could use to check whether the calendar is still active or not.

    I would like to reschedule the timertask if the original schedule was disrupted.

    timertasks should not be used for the treatment of blocking. I would say to put the actual work load in an own thread.

    as long as the enforcement code is surrounded by exception handling, execution continues. There is no method to check if the timer is running correctly.

  • Error of IllegalStateException BlackBerry using TimerTask

    Hello

    I have a splash screen that implements form, and I'm trying to use the timer to wait 3 seconds to press a new screen.

    TimerTask splashTask = new TimerTask() {
            public void run() {
                UiApplication.getUiApplication().pushScreen(new HomeNavigationScreen());
            }
        };
    
        timer.schedule(splashTask, 3000);
    

    However, it throws IllegalStateException error, I'm not sure what I am doing wrong?

    Check This...

    http://supportforums.BlackBerry.com/T5/Java-development/loading-screen/TD-p/556826

    Its the same problem, I guess that

  • RunTimeException when you use the timer and TimerTask.

    In the switchNext() method, it changes an image and some text in a Vertical management. When I run the application, I get a RunTimeException. However, when I have not used the timer and tested the method switchNext() with just a button method worked perfectly. How can I make it work with timer or another class that he will call every 30 seconds?

     time = new Timer();
    TimerTask task = new TimerTask()
    {
    
    public void run()
    {
    
        switchNext();
    }
    };
    time.schedule(task, 10000);
    

    It would be useful to know what Exception you actually get.

    However, I think that it is indeed related to the fact IllegalStateException the TimerTask is running in the "bottom", and you try to update your User Interface.

    If you change the code as follows, it will work the method on the event Thread and so he has access to update the user interface.

    public void run()
    {
    UiApplication.getUiApplicat () .invokeLater (new Runnable()

    public void run() {}
    switchNext();

    }});
    }

    You can find more information on the event thread here:

    http://supportforums.BlackBerry.com/T5/Java-development/what-is-the-event-thread/Ta-p/446865

Maybe you are looking for

  • IZotope Ozone plugin disappeared from FCPX

    IZotope Ozone 6 is still on my computer and I can run as a stand-alone, but it is no longer available in my effects.  How do I re - install?  I don't remember having to do anything a year when I bought it; Just recognized FCPX and let me use it as a

  • HP Pavilion TouchSmart 11-e012au max memory

    Hi all as topic, someone knows max ram for my laptop and what brand that was more compatible with my system? regrads

  • I have a pop up of mystery that began

    I have a pop up of mystery that began and acts as a virus pop up but is in the form of a search page.  I ran MS malicious software malware tool, but he found nothing. I ran also 4 other alware programs removal and found nothing. What is this and how

  • ePower Management and update of Windows 7 (March 12, 2013)

    Has anyone else had a message of compatibility for the ePower Management with the latest update of Windows 7.  Acer response was to send the laptop... Right.

  • Directory/folder for file transfers locations

    I am trying to transfer my music, ringtones for my new atrix 4 g, and from what I have gathered various assignments that I do with records separated for everything... such as notifications, ringtones and SMS ringtones seems a little silly to me given