timer

How to convert CRON string to ScheduleExpression in Java?

二次信任 提交于 2019-12-12 21:21:38
问题 I got this problem: I have a text field, There should be a CRON expression written, and later on saved. Now I need a method to convert the CRON string (here are some random examples: http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html) to java ScheduleExpression (http://docs.oracle.com/javaee/6/api/javax/ejb/ScheduleExpression.html) But, I have no idea how to do it... I have a timer based execution system, that run only on days, weeks and months, but now I need

Scheduled Task in Fragment returns getActivity as null

陌路散爱 提交于 2019-12-12 21:05:59
问题 I know similar type of question is asked before. Sorry to ask again. I have a fragment in a tab FragmentActivity. Within the fragment in onActivityCreated , I have to schedule a task after every fix interval. Timer t = new Timer(); t.scheduleAtFixedRate(new TimerTask() { @Override public void run() { getActivity().runOnUiThread(new Runnable() { @Override public void run() { new fetchDataInBackground(ctx).execute(); //async task } }); } }, 0, 20000); The above code works perfectly fine, until

Timer inside Android service

微笑、不失礼 提交于 2019-12-12 20:23:54
问题 I have an Android service that starts a timer that does stuff: @Override public int onStartCommand(Intent intent, int flags, int startId) { timer.scheduleAtFixedRate(new VeryImportantTask(), 0, RATE); return START_STICKY; } I know Services are singleton but, does onStartCommand method called each time that I call startService() ? If so, I should control that my timer is just started the first time, shouldn't I? I'm thinking in a static boolean flag in the service. Is there a better way? 回答1:

Clock in Javascript

落爺英雄遲暮 提交于 2019-12-12 20:06:33
问题 I have made a clock in javascript but its a static clock. What changes I need to do in the following code so that it updates with every second. <html> <head> <title>Javascript Clock</title> <script type="text/javascript"> function clk() { var a=new Date(); document.getElementById("disp").innerHTML=a.getHours() + ":" + a.getMinutes() + ":" + a.getSeconds() ; } </script> </head> <body> <input type="button" onclick="clk()" value="Display Clock" /> <p id="disp">Clock Space</p> </body> </html> 回答1

Swift - Timer doesn't stop

被刻印的时光 ゝ 提交于 2019-12-12 19:44:25
问题 I have the following code: class firstVC: UIViewController { var timer : Timer? func scheduledTimerWithTimeInterval(){ timer = Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(self.anotherFunc), userInfo: nil, repeats: true) } override func viewDidAppear(_ animated: Bool) { scheduledTimerWithTimeInterval() } } I'm trying to stop the timer without success: func stopTimer() { if timer != nil { timer?.invalidate() timer = nil } } override func viewDidDisappear(_ animated:

Is there a way to auto-power on the phone

梦想与她 提交于 2019-12-12 19:38:36
问题 I want to do a custom Timer app. I want it can start up and shutdown. I searched and found that starting it up needs root rights. Can anyone give me some clue to finish this? Edit: in other words:It seems nice to have an app to auto power on or power off the phone, does the hardware support?The app is only for users to set time when to turn on the phone or power off. How to turn on the phone when it is power off? If we power off our phone or take out battery, the clock still show us a correct

Android dataBinding - unable to notify view of changes

一笑奈何 提交于 2019-12-12 19:10:27
问题 i am trying to use databinding for a purpose. I have a project i've created that starts a countdown timer. If the time is a prime number it should update a TextView in a xml layout. The timer works fine but the textview never gets updated. here is my timer which works fine: public class MyCountDownTimer { private CountDownTimer countDownTimer; private boolean isExecuting =false; private ICountDownListener listener; private final String TAG = getClass().getSimpleName(); public MyCountDownTimer

How to modify a java timer interval after scheduling it for a fixed rate in android? [duplicate]

随声附和 提交于 2019-12-12 18:23:09
问题 This question already has answers here : Pausing/stopping and starting/resuming Java TimerTask continuously? (8 answers) Closed 4 years ago . I have a service which has one Timer. I call timer.scheduleAtFixedRate() in the onStart() callback method. But I have to alter the timer interval depending on the value of a variable. I found no function for timer to alter its interval. So I thought to cancel the timer and re-schedule when that condition is met. But I am checking the condition with in

Clock_nanosleep() does not yet support CLOCK_MONOTONIC_RAW. How to deal with this?

橙三吉。 提交于 2019-12-12 16:55:47
问题 Currently clock_nanosleep with CLOCK_MONOTONIC_RAW on Debian Jessie returns EOPNOTSUPP. How to work around the issue and compensate for possible NTP adjustments which might get applied to CLOCK_MONOTONIC in the timer loop? Is clock_nanosleep itself also affected by NTP adjustments? If adjustments happen while sleeping, will clock_nanosleep sleep longer that expected? And should I be worried at all about possible CLOCK_MONOTONIC NTP adjustments in my specific case? What would be the largest

How to stop a timer in java

拟墨画扇 提交于 2019-12-12 16:52:52
问题 I have a method called timer that I run everytime a user inputs something and the timer is scheduled for a minute, but I want the timer to cancel if the user enters something in less than a minute and then recall itself so the whole process happens again. My methods are below: Input method public static String run(){ timer(); //runs everytime I call run() String s = input.nextLine(); return s; } Timer method public static void timer() { TimerTask task = new TimerTask() { public void run() {