Possible Duplicate:
How to set Alarm in Android?
I in my application am using Date and Time,But I don't know how set reminder like alarm which will remind 5 min before,10 min before via mail and also on time Popup message display on screen.
Possible Duplicate:
How to set Alarm in Android?
I in my application am using Date and Time,But I don't know how set reminder like alarm which will remind 5 min before,10 min before via mail and also on time Popup message display on screen.
Here is an very easy timer but works great!
Declaration of Handler:
private Handler mHandler = new Handler();
Declaration of Runnable:
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
final long start = mStartTime;
mStartTime = 0L;
long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
// do things after 'timerTime' expired.
mHandler.postAtTime(this,
start + (((minutes * 60) + seconds + 1) * 1000));
}
};
Start timer if its not already running:
if (mStartTime == 0L) {
mStartTime = System.currentTimeMillis();
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(mUpdateTimeTask, timerTime);
}
If you want a reminder even your activity is not in view, you have to put this in a service class. After the Time is expired you can send an eMail in background or fire a notification via PendingIntent.