Ответ 1
Содержимое, взятое из блога Планирование задачи с помощью Alarm Manager в Android
public void scheduleAlarm(View v)
{
// The time at which the alarm will be scheduled. Here the alarm is scheduled for 1 day from the current time.
// We fetch the current time in milliseconds and add 1 day time
// i.e. 24*60*60*1000 = 86,400,000 milliseconds in a day.
Long time = new GregorianCalendar().getTimeInMillis()+24*60*60*1000;
// Create an Intent and set the class that will execute when the Alarm triggers. Here we have
// specified AlarmReceiver in the Intent. The onReceive() method of this class will execute when the broadcast from your alarm is received.
Intent intentAlarm = new Intent(this, AlarmReceiver.class);
// Get the Alarm Service.
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// Set the alarm for a particular time.
alarmManager.set(AlarmManager.RTC_WAKEUP, time, PendingIntent.getBroadcast(this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
Toast.makeText(this, "Alarm Scheduled for Tomorrow", Toast.LENGTH_LONG).show();
}
Класс AlarmReceiver
public class AlarmReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// Your code to execute when the alarm triggers
// and the broadcast is received.
}
}