Skip to content Skip to sidebar Skip to footer

Timer Inside Android Service

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 VeryIm

Solution 1:

In your case i.e START_STICKY you can simply check the intent value nullity like this

@OverridepublicintonStartCommand(Intent intent, int flags, int startId) {
      if(null==intent){
              // service restarted do what you want
        }
    return START_STICKY;
}

because first time the intent will not be null and it will be null every time in case of a restart with START_STICKY.

Post a Comment for "Timer Inside Android Service"