I'd suggest a Service so you won't miss the date even if your app wasn't running or just create a timer in your activity
create a service and add it in your application manifest.xml
public class DateCheckService extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// add a timer here to check date, check below for code
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}
create timer in activity or service.
Timer timer = new Timer();
class DateCheckTask extends TimerTask {
public void run() {
//calculate date and take action
}
}
finally add the task to the Timer with update interval
TimerTask dateCheckTask = new DateCheckTask ();
timer.scheduleAtFixedRate(dateCheckTask , 0, 10);//interval of 10unit