I basically want a stopwatch activity in my app that will vibrate the device after 30 seconds have elapsed and sound a notification alert at 60 seconds. I am new to app development so please don't hound me for missing an obvious answer.
I know I need Chronometer.OnChronometerTickListener
- but not sure how to implement?
public void shotClockStart(View v) {
Chronometer shotclock = (Chronometer) findViewById(R.id.chrono1);
shotclock.start();
long timeElapsed = SystemClock.elapsedRealtime() - shotclock.getBase();
if (timeElapsed >= 30000) {
// HERE I WANT A VIBRATION ON THE DEVICE.
}else if(timeElapsed>=60000){
//HERE I WANT A NOTIFICATION ALERT
}
}
You have to set the listener on the Chronometer
public void shotClockStart(View v) {
Chronometer shotclock = (Chronometer) findViewById(R.id.chrono1);
shotclock.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer chronometer) {
long timeElapsed = SystemClock.elapsedRealtime() - chronometer.getBase();
if (timeElapsed >= 30000) {
// HERE I WANT A VIBRATION ON THE DEVICE.
}else if(timeElapsed>=60000){
//HERE I WANT A NOTIFICATION ALERT
}
}
});
shotclock.setBase(SystemClock.elapsedRealtime());
shotclock.start();
}