I am working on an alarm feature for my application where, at a certain time, an alarm Activity is started, which subsequently starts either a vibration or a ringtone. The problem I've run into is that the vibration or ringtone is not stopped if the user presses the Home button.
I have overriden onKeyDown
so that the alarm is stopped when a button is pressed, but that does not intercept the Home button code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (mVibrator != null)
mVibrator.cancel();
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
}
return super.onKeyDown(keyCode, event);
}
How can I go about stopping the vibration/ringtone when this occurs?