Chintan Soni
Chintan Soni

Reputation: 25267

set date and time from respective pickers to set alarm

I preparing an app like "To-Do List" in which user sets alarm to its task. Now the problem is that i don't know how to set alarm using date and time pickers.

The working i need is that user first selects date and then time. This date and time is to be used to set Notification on this specified date and time. And after clicking on that notification, the activity that contains whole to do list starts. In that activity, once the to do task is marked finish, the alarm must be removed from that specific date and time.

Please someone help me. I am trying this for the first time. Please help me learning this.

PS: The work i've done till now is, i have the prepared an activity that takes necessary details about task such as task brief, task priority, task date task time, and i am storing it in database. I can successfully mark the task done / undone. The work i'm remaining with is setting the Notification about that task.

Upvotes: 0

Views: 179

Answers (1)

Vallabh Lakade
Vallabh Lakade

Reputation: 832

find the difference between the current time and the time at which the work id to be done in milliseconds and set it to alarm.

AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);        
    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * diffInMillis , pi);

Hope it helps

Upvotes: 1

Related Questions