Intent myIntent = new Intent(Alarm.this, Automaton.class);
myIntent.putExtra("methodName", "myMethod");
myIntent.putExtra("hour", tp.getCurrentHour().toString());
myIntent.putExtra("minute", tp.getCurrentMinute().toString());
hour = tp.getCurrentHour();
minute = tp.getCurrentMinute();
PendingIntent pendingIntent = PendingIntent.getActivity(Alarm.this, 0, myIntent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.HOUR_OF_DAY, hour);
calendar.set(calendar.MINUTE, minute);
calendar.set(calendar.SECOND, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 86400000, pendingIntent);
以上是我的代码。这是我的问题;我想在指定时间运行另一个 Activity 中的方法。如果用户选择了一天中还没有过去的时间(假设您将闹钟设置为上午 10 点到上午 11 点,它会正常工作)。但是,如果您将上午 9 点的闹钟设置为上午 10 点,它会立即触发 Pending Intent。不知道我哪里出错了。任何帮助,将不胜感激!