@Override public void onDestroy() { Log.i(TAG, "onDestroy"); // Cancel the ongoing notification. mNM.cancel(TIMER_NOTIFICATION); mHandler.removeMessages(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; }
public void stopTimer() { mHandler.removeMessages(0); stopSelf(); mNM.cancel(TIMER_NOTIFICATION); }