Hello,
do not use sleep in background services, Android can think that Your service is not working (especially in energy save mode) and try to kill. Instead of this use for example :
const cTimeInterval = 30000;
var aLastTime : TDateTime;
begin
aLastTime := Now(); // use aLastTime := Now()-1; (whatever to start imiditly)
while true do
begin
if (MilliSecondsBetween(Now(),aLastTime)>=cTimeInterval) then
begin
aLastTime := Now();
// do somethink there
end;
end;
end;
if You need to have time interval counting after to do something move aLastTime := Now(); after work you need to make. For me works better if I create that in new Thread in service.
while true do - you can change to do somethink to brake loop if you need
best regards
Moskw@