我需要在特定时间运行服务,而我正在使用AlarmManager。但这不会触发我的BroadcastReceiver类来启动我的服务。
即使在调试模式下,它也不会通过我在BroadcastReceiver类中设置的断点。
private void nightTaskStart() {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY,10);
c.set(Calendar.MINUTE,56);
c.set(Calendar.SECOND,5);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, NightTaskReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 2, intent, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pi);
}
我的BroadcastReceiver类:
public class NightTaskReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent nightIntent = new Intent(context, GetdataService.class);
context.startService(nightIntent);
Log.d("damn","daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaamn");
}
}
有很多类似的问题,但都无济于事。