I am writing app, which include service and timer. User set time of Timers. Timer must every day make work(even night). Timer (and service) is working when telephone active, but when telephone goes into sleep mode timer doesn't work(service still work). May be I must use the Handler with timer how here: Android timer? How-to? or I must use PowerManager and forcibly not allowed to sleep telephone?
I use timer within service
public class SampleService extends Service {
....
public int onStartCommand(Intent intent, int flags, int startId) {
my_timer_start();
}
my_timer_start();{
ltimer = new Timer();
ltimer.scheduleAtFixedRate(new My_task(), time1, every_hour);
}
class My_task implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
...........................
}
}
void cancel_task() {
ltimer.cancel();
ltimer = null;
}
public void onDestroy() {
super.onDestroy();
cancel_task();
}
}
thanks for the help!