I am a newbie in android. I am developing an app in which a particular piece of code executes after every 5 seconds in background.To achieve this I am using a service with timer with a timer task in it. For sometime its working fine but after some indefinite my service is running but timer task stops automatically in android. Here is my code please help. Thanks in advance.
public void onStart(Intent intent, int startid) {
//this is the code for my onStart in service class
int delay = 1000; // delay for 1 sec.
final int period = 5000; // repeat 5 sec.
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
executeCode();
}, delay, period);
};