예제 #1
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "Received start id " + startId + " with intent: " + intent);

    // Show notification when we start the timer
    showNotification();

    mStart = System.currentTimeMillis();
    mHandler.removeMessages(0);
    mHandler.sendEmptyMessage(0);

    // Keep restarting until we stop the service
    return START_STICKY;
  }
예제 #2
0
  @Override
  public void onDestroy() {
    Log.i(TAG, "onDestroy");
    // Cancel the ongoing notification.
    mNM.cancel(TIMER_NOTIFICATION);

    mHandler.removeMessages(0);
  }
예제 #3
0
 public void stopTimer() {
   mHandler.removeMessages(0);
   stopSelf();
   mNM.cancel(TIMER_NOTIFICATION);
 }
예제 #4
0
 public boolean isTimerRunning() {
   return mHandler.hasMessages(0);
 }