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點,那麼它將工作正常)。但是,如果您在上午10點將鬧鐘設置爲9AM,則會立即觸發待定意向。不知道我哪裏錯了。任何幫助,將不勝感激!AlarmManager點火報警即時
謝謝你的快速反應APPU,可以說我現在要設置鬧鐘(下午11:45)至明天5:30 AM運行。從技術上講,上午5點半已經過去了,所以如果我去設置它,它會立即啓動。這就是我想要避免 – user2121927
不,我可以說你明白事情是錯誤的。因爲鬧鐘應該在毫秒的幫助下設置。因此,現在以毫秒爲單位的11.45PM技術上明天小於5:30 AM(以毫秒爲單位) – Kanth