我的应用程序中有此代码
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 11);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.AM_PM,Calendar.AM);
//Debug!!!!!
//calendar.set(Calendar.SECOND, Calendar.SECOND+5);
Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY ,pendingIntent);
理论上它会在每天上午 11:30 设置一个警报,但实际上它会在每次应用程序启动时触发此警报,或者当我返回主要活动时。我想每天在这个特定时间显示这个闹钟