我正在做一个闹钟的应用,下边的这个是运行闹钟的方法:
public void startAlarm(int minuteToStart)
{
Toast.makeText(context, "Alarm Start in " + formatTime(minuteToStart), Toast.LENGTH_SHORT).show();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, minuteToStart);
Intent intent = new Intent(context, AlarmActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, idPendingIntent, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
}
在特定的时间后它就会运行这个activity:
public class AlarmActivity extends Activity {
......
}
它起作用,但是我看到大家都用BroadcastReceiver,是我做错了?我不是也应该用BroadcastReceiver?我已经查了BroadcastReceiver,但是我不知道他在我的应用中会起什么作用。