警报管理器未在指定时间准确触发广播接收器

时间:2014-07-19 09:02:00

标签: android android-pendingintent android-alarms android-broadcast

要求:我想每隔3分钟触发一次警报并执行广播接收器,但警报并不是每3分钟触发一次,这是我的代码,任何帮助??

警报管理器

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent in = new Intent(this,GPSReceiver.class);
PendingIntent pi =  PendingIntent.getBroadcast(this,234324243, in, 0);

Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
am.setRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 3*60*1000, pi);
Log.i("hei",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").format(cal.getTimeInMillis())); 

广播接收器

public class GPSReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

    Log.i("hei","GPSReceiver Called");
    Calendar cal = Calendar.getInstance();
       }
}

根据上面的代码,警报按以下顺序触发(但并不总是按照下面提到的相同顺序)

07-19 14:11:53.194:I / hei(30310): 2014-07-19 14:11:53.202

07-19 14:11:53.194:I / hei(30310):被叫GPSReceiver

07-19 14:12:03.061:I / hei(30310): 2014-07-19 14:12:03.68

07-19 14:12:03.061:I / hei(30310):被叫GPSReceiver

07-19 14:14:53.186:I / hei(30310): 2014-07-19 14:14:53.194

07-19 14:14:53.186:I / hei(30310):被叫GPSReceiver

07-19 14:15:03.030:I / hei(30310): 2014-07-19 14:15:03.36

07-19 14:15:03.030:I / hei(30310):被叫GPSReceiver

07-19 14:17:53.186:I / hei(30310): 2014-07-19 14:17:53.193

07-19 14:17:53.186:I / hei(30310):被叫GPSReceiver

07-19 14:18:03.030:I / hei(30310): 2014-07-19 14:18:03.38

07-19 14:18:03.030:I / hei(30310):被叫GPSReceiver

0 个答案:

没有答案