AlarmManager没反应,求指教

主体:

am = AlarmManager getSystemServiceService.ALARM_SERVICE;
Intent intent = new Intentthis,MyAlarmBroadCast.class; PendingIntent pi = PendingIntent.getActivitythis, 0, intent, 0; am.setAlarmManager.RTC_WAKEUP, 10*1000, pi;

接收器:

public class MyAlarmBroadCast extends BroadcastReceiver{ @Override public void onReceiveContext context, Intent intent { Toast.makeTextcontext, "闹钟提示:时间到!", Toast.LENGTH_LONG.show; } }

mainifest.xml
<receiver android:name=".MyAlarmBroadCast"> <intent-filter> <action android:name="com.example.energyup.MyAlarmBroadCast" /> </intent-filter> </receiver>

am.setAlarmManager.RTC_WAKEUP, 10*1000, pi;

的第二个参数的理解有问题,这里传入的时唤醒准确时间,并不是间隔,按你的需求,应该是

am.setAlarmManager.RTC_WAKEUP, System.currentTimeMillis+10*1000, pi;

看看文档中对RTC时间的解释

发表评论

电子邮件地址不会被公开。 必填项已用*标注