I have an Android service that starts a timer that does stuff:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
timer.scheduleAtFixedRate(new VeryImportantTask(), 0, RATE);
return START_STICKY;
}
I know Services are singleton but, does onStartCommand
method called each time that I call startService()
? If so, I should control that my timer is just started the first time, shouldn't I? I'm thinking in a static boolean flag in the service. Is there a better way?