Questions tagged [timertask]

Timertask is a Java API class. Logically it represents a task that can be scheduled for one-time or repeated execution by a Timer

A TimerTask implements Runnable, also has a method to cancel the scheduled task, if required. It is used with java.util.Timer (Swing timer fires action events).

A concurrent package contains several classes that are similar to TimerTask by concept but provide additional funcitonality.

917 questions
3
votes
2 answers

How can I implement a Timer/TimerTask that executes an AsyncTask? (Android)

I'm trying to perform a task (ie. load data from a text file) asynchronously and repeatedly at specified times (ie. every few seconds, though this rate may change at runtime). I have done some research and decided that this will require either an…
3
votes
3 answers

Clear the label before calling a JavaScript function which displays timer through the same function [Session Timeout]

I tried to display timer on webpage in label (label id is MsgTimer) using following function. But when the function is called the 2/more times then 2/ more timers are displayed and it won't reset the timer but overload the label text and display…
3
votes
1 answer

why mediaplayer getcurrentposition returns lower than before?

I'm trying to make a seekbar which shows playback position And I found something weird. The value of current position it not inscreasing. It should be increased by asc. Log D/RecordingFragment: #@ current_position: 0 D/RecordingFragment: #@…
3
votes
1 answer

Time limit for an input inside a loop

I want to implement a feature where user need to give a input in fixed time limit. I have gone through this answer. Time limit for an input This example works one time. When user not giving input in fixed, programe is terminating. But i'm trying to…
3
votes
0 answers

2018 alternative to Timer and TimerTasks

I have some very old (mid 2000s) code that instantiates objects based on incoming data from network IO, and each of these objects contains a private (non-static) timer and kicks off a scheduled TimerTask corresponding to a serialized object that…
Smrtnik
  • 43
  • 3
3
votes
2 answers

service automatically stops after several minutes

I'm creating a service which should work when the activity is in background as well as when the whole application is destroyed. I'm calling location coordinates in the service at every 1 minute interval. However, when I try to do so, the service…
Vikas singh
  • 3,461
  • 3
  • 14
  • 28
3
votes
2 answers

Java - Reusing Timer Object after calling cancel

I have an application in Java where I need to schedule a TimerTaskwhich will be executed after 500ms , however if a certain event occurs, I must reset the timer for this task (so that we must wait another 500ms for it to execute). I have a timer…
Alk
  • 5,215
  • 8
  • 47
  • 116
3
votes
0 answers

Android: TimeOut on WebViewClient

I am trying to implement a TimeOut error handling on a webview. But unfortunately I am doing something wrong, which is causing me huge headaches. Currently I am using a TimerTask. To check the progress of a webpage for 10 seconds. The idea is if the…
user3182266
  • 1,270
  • 4
  • 23
  • 49
3
votes
2 answers

Timer task to schedule multiple jobs

Please find my requirement here.I have a InvokeTimer class which invokes TimerClass for every sec/min/hour.In the runnable of TimerClass in need to execute a logic when timer is triggered for every sec i.e if its instance of stats1 and other logic…
cmahi
  • 43
  • 3
3
votes
1 answer

Android : Stopping works Widget when user removes app from recent tasks list

I have a Timer in my app widget. This timer will be updating the Widget UI every second. All the process works perfectly. But, when user removes my app from recently apps task list, timer stops immediately. Anybody knows how to fix this problem?
SBotirov
  • 13,872
  • 7
  • 59
  • 81
3
votes
1 answer

Timer Delay Problems Java

I am trying to make a snake type game and I am having trouble making the "pellets" appear at random places at fixed intervals (I want to make it 10 seconds). When I run the program after the brief delay I gave it (1000 milliseconds) the pellets…
Saliva
  • 63
  • 5
3
votes
2 answers

How to implement the timer to run inside Alarm Receiver even after the app quits?

I have used Alarm Service. I have implemented the the alarm to run on every 1 minute. So the broadcast receiver onReceive method gets called even after the app quits. I want to implement a timer inside of this onReceive method. I have to start…
M Vignesh
  • 1,586
  • 2
  • 18
  • 55
3
votes
1 answer

OutOfMemoryError by using java.util.Timer

Timer mTimer; void scheduleSyncIn(int aSeconds){ if (mTimer != null) { mTimer.cancel(); mTimer = null; } mTimer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { …
Nikhil
  • 1,023
  • 17
  • 35
3
votes
1 answer

Timer and TimerTask - how to reschedule Timer from within TimerTask run

basically what I want to do is to make a Timer that runs a specific TimerTask after x seconds, but then the TimerTask can reschedule the Timer to do the task after y seconds. Example is below, it gives me an error "Exception in thread "Timer-0"…
user3885166
  • 217
  • 2
  • 11
3
votes
1 answer

Why does scheduleAtFixedRate(task, delay, period) not work as scheduled?

I am to use a timer using timertask to check the wifi status after every minute in an android app. Here I have to check whether wifi radio is on or off after every minute. If the wifi radio is off I have to turn it on and when wifi radio is on the…
vidulaJ
  • 1,232
  • 1
  • 16
  • 31