0

I am a newbie in android. I am making an app in which some task has to be repeated after every specified time say 15 seconds. I am using a service for this. It works fine for sometime but my problem is it stops after any indefinite dont know whats the reason. I am using Timer.Schedule with Timertask thread in it. Please Help. Thanks in advance.

user1508383
  • 95
  • 2
  • 11

1 Answers1

0

You must be writing your actual code inside the onStart(Intent intent, int startId). If the service is already running in the background, Android wont call the onStart method on the start of service.It calls onStartCommand method, Put the logs in both methods then you will get to know.

public void onStart(Intent intent, int startId) {
    executeCode();
}

public int onStartCommand(Intent intent, int flags, int startId) {
    executeCode();

    return 0;
}

Thanks.

Om Narain Shukla
  • 361
  • 1
  • 4
  • 12