【发布时间】:2019-05-15 15:01:59
【问题描述】:
我正在使用日历对话框询问用户时间的调度程序应用程序。然后我使用AlarmManager安排任务,你可以看到下面的代码。
Log.d("SchedulerTag", "sendMessageLater: " + new Date(timeInMillis));
Intent intent = new Intent(getApplicationContext(), AlarmReceiver.class);
intent.putExtra("message", message_string);
intent.putExtra("number", end_number);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
Toast.makeText(this, "Message Scheduled Successfully", Toast.LENGTH_SHORT).show();
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, timeInMillis, pendingIntent);
Toast.makeText(this, "Message Scheduled Successfully", Toast.LENGTH_SHORT).show();
}
在此之后,我使用 AlarmReceiver 类接收它,代码
public void onReceive(Context context, Intent intent) {
//some code her
}
问题是,任务没有安排在正确的时间,无论选择什么时间,它只会在 10 分钟后被调用
我的清单包含接收器。我做错了什么?
【问题讨论】:
标签: android scheduled-tasks alarmmanager scheduler