Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus
Accepted Solution

Timer not working

[ Edited ]

Hi everyone. I'm trying to push a screen after my application has been idle for some time. I'm using the code here: http://supportforums.blackberry.com/t5/Java-Development/Detect-Idle-time-of-device/m-p/536925

 

 

Calendar c11 = Calendar.getInstance();
Date dt =  c11.getTime();    
Timer tim = new Timer();
tim.schedule(new CD(),dt,60000);//set for 1min in millisecs

 

Calendar c11 = Calendar.getInstance(); Date dt =  c11.getTime();     Timer tim = new Timer(); tim.schedule(new CD(),dt,60000);//set for 1min in millisecs

 

which is in my onExposed().

 

mt timertask is as follows:

 

 

public class CD extends TimerTask

{

  public CD() {    }    

  /*For Every 1min the control will pass through this method */ 

  public void run() 

  {

   if(DeviceInfo.getIdleTime() >= 60  )/*if its idle for 10mins*/  

   {       

    UiApplication.getUiApplication().pushScreen(new ClockScreen());

   }                

 }

}

 

nothing seems to happen though.

Highlighted
Developer
Posts: 62
Registered: ‎10-29-2008
My Device: 9800
My Carrier: Rogers

Re: Timer not working

First off, detecting the idle time of your application vs the idle time of the device are two totally different things.

 

You application could be running in the background doing nothing for days while other things are happening in other applications, such as you checking email, surfing the web, handling phone calls, etc. so this may not be the best solution for you.

 

I would suggest setting a timer on your onExposed set for 60 seconds, then each time the screen is exposed you check that timer and re-update the time at which it should launch.

 

Finally, I don't believe the way that you're calling the timer function will work properl

 

Check out the JavaDoc for more info on how to properly construct a timer http://www.blackberry.com/developers/docs/5.0.0api/java/util/Timer.html

 

You're most likely going to want to use this

 

schedule(TimerTask task, long delay) 

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Timer not working

[ Edited ]

Agree with the previous poster.

 

I'm wondering if you consider your application as idle, if it has been put into the background?  If not, then you might consider integrating some code into activate and deactivate. 

Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Timer not working

Well my app is triggered by a usbconnectionstatechange then my app requests foreground. If this screen is left idle for say 5 mins I want to push another screen. So rnickel is right I don't want the device's idle time but my app's