为什么每次刻录新的apk时,该警报管理器是否先运行预定警报?

时间:2015-11-06 12:33:38

标签: android broadcastreceiver scheduled-tasks alarmmanager

我要求我在不同的时间安排不同的报警管理器,如下所示。

private void SetAlarmforFirst(Context context, String value, String PrimaryText) {
        String[] labelLanguage = value.split(":");
        Calendar updateTime = Calendar.getInstance();
        updateTime.setTimeZone(TimeZone.getDefault());
        updateTime.set(Calendar.HOUR_OF_DAY, 10);
        updateTime.set(Calendar.MINUTE, 45);
        Intent downloader = new Intent(context, AlarmReceiver.class);
        downloader.putExtra("STRING_I_NEED", PrimaryText);
        PendingIntent recurringDownload = PendingIntent.getBroadcast(HomeScreen.this, 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager alarms = (AlarmManager) HomeScreen.this.getSystemService(Context.ALARM_SERVICE);
        alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, recurringDownload);
    }

    private void SetAlarmforSecond(Context context, String value,String PrimaryText) {
        String[] labelLanguage = value.split(":");
        Calendar updateTimeSecond = Calendar.getInstance();
        updateTimeSecond.setTimeZone(TimeZone.getDefault());
        updateTimeSecond.set(Calendar.HOUR_OF_DAY, 15);
        updateTimeSecond.set(Calendar.MINUTE, 20);
        Intent downloaderSecond = new Intent(context, AlarmReceiver.class);
        downloaderSecond.putExtra("STRING_I_NEED", PrimaryText);
        PendingIntent recurringDownloadSecond = PendingIntent.getBroadcast(HomeScreen.this, 1, downloaderSecond, PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager alarmsSecond = (AlarmManager) HomeScreen.this.getSystemService(Context.ALARM_SERVICE);
        alarmsSecond.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTimeSecond.getTimeInMillis(), AlarmManager.INTERVAL_DAY, recurringDownloadSecond);
    }

    private void SetAlarmforThird(Context context, String value, String PrimaryText) {
        String[] labelLanguage = value.split(":");
        Calendar updateTimethird = Calendar.getInstance();
        updateTimethird.setTimeZone(TimeZone.getDefault());
        updateTimethird.set(Calendar.HOUR_OF_DAY, 16);
        updateTimethird.set(Calendar.MINUTE, 10);
        Intent downloaderThird = new Intent(context, AlarmReceiver.class);
        downloaderThird.putExtra("STRING_I_NEED", PrimaryText);
        PendingIntent recurringDownloadThird = PendingIntent.getBroadcast(HomeScreen.this, 2, downloaderThird, PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager alarmsThird = (AlarmManager) HomeScreen.this.getSystemService(Context.ALARM_SERVICE);
        alarmsThird.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTimethird.getTimeInMillis(), AlarmManager.INTERVAL_DAY, recurringDownloadThird);
    }

当我对任何一个警报管理器的时间进行任何更改并再次运行应用程序时,它不是运行已更改的警报管理器,而是仅在先前的警报管理器时间小于新安排的。

你可以告诉我我在哪里做错了。谢谢。

0 个答案:

没有答案