Reputation: 192
I am trying to instantiate a function(method1()
) from an activity(act1.java
) automatically for every 24 hours. I have checked some other tutorials, which demonstrated the usage of TimerTask and AlarmManager. But, there I am unable to understand the flow of the code. Can any one please provide me some sample code, or tutorials, so that I can get an idea of using TimerTask
and AlarmManager
.
These are the tutorials I have checked -
Thanks in advance.
Upvotes: 0
Views: 167
Reputation: 34424
why not use ScheduledExecutorService which is designed to schedule commands to run after a given delay, or to execute periodically.
private final ScheduledExecutorService taskScheduler = Executors.newScheduledThreadPool(1);
taskScheduler .scheduleAtFixedRate(yourRunnable, 0, 24, HOURS);
Also consider Quartz Scheduling which is useful if you are using scheduling jobs extensively in your project. More maintainable.
Upvotes: 1