I've stored a date in a database, but if now I want to execute some code when the date stored is equal to the corrent date on the device? The date format is : MM/DD/YYYY , if for example the date stored is 03/14/2015 and I need to execute code in 03/14/2015 at 00.00?
Asked
Active
Viewed 218 times
0
-
Basically build an Alarm Clock inline with the various examples you can find thereof, only use your database to keep track of your alarms. – Chris Stratton Mar 13 '15 at 12:22
-
@ChrisStratton what do you mean for "keep track of your alarms."? – Slaiv206 Mar 13 '15 at 12:24
-
You will understand that when you start examining practical code as suggested. In particular, there are circumstances where you will need to re-load your alarm time into the APIs involved, so you have to keep track of them for that. A simple alarm clock will do it just for that purpose, but you already have them in a database. – Chris Stratton Mar 13 '15 at 12:29
-
Dude, don't store dates in USA format. Use ISO. Display dates according to the device preferences. – danny117 Mar 13 '15 at 14:20
1 Answers
0
You need to use a Broadcast receiver that will invoke when system date is changed.Use this approach and following code would help
in android manifst
<receiver android:name=".DateTimeChangeReceiver ">
<intent_filter>
<action android:name="android.intent.action.DATE_CHANGED"/>
</intent_filter>
</receiver>
DateChangeReceiver
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class DateTimeChangeReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, "Date changed", Toast.LENGTH_SHORT).show();
/*Compare databae date with current system date. you can get system date using calender. and execute your code according to your need. */
}
}
I hope this will help you out.

Waqar Mahmood
- 56
- 4