我想做简单的闹钟。我知道重启后我的所有闹钟都会被清除。如何在设备重启后保留所有警报? 这就是我设置闹钟的方法:
Button button = (Button) findViewById(R.id.button1);
final TimePicker timePicker1 = (TimePicker) findViewById(R.id.timePicker1);
final Intent intent1 = new Intent(MainActivity.this,myReceiver.class);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar1 = Calendar.getInstance();
calendar1.set(Calendar.MINUTE, timePicker1.getCurrentMinute());
calendar1.set(Calendar.HOUR_OF_DAY,timePicker1.getCurrentHour());
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
PendingIntent pi1 =PendingIntent.getBroadcast(MainActivity2.this,0,intent1,0);
am.set(AlarmManager.RTC,calendar1.getTimeInMillis(),pi1);
}
});
答案 0 :(得分:0)
保存您想要的闹钟并创建一个接收器,将它们全部设置为启动。
Android BroadcastReceiver on startup - keep running when Activity is in Background