AlarmManager does not work on time

I want it to AlarmManagerbe launched at 10:30 daily, depending on the time of the user's mobile device. He shoots at 10:30, but the problem is that after 10:30 in the morning he repeats without time, like after every hour or after any unusual time interval.
How to prevent this problem? I find it on the Successful Login and Registration Event ButtonCick(). I also want to stop this if the user logs out. My code is as follows:

        Intent myIntent = new Intent(Register.this, AlarmReceiver.class);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(Register.this,
                0, myIntent, 0);

        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

        Calendar firingCal = Calendar.getInstance();
        Calendar currentCal = Calendar.getInstance();

        firingCal.set(Calendar.HOUR_OF_DAY, 10);
        firingCal.set(Calendar.MINUTE, 30);
        firingCal.set(Calendar.SECOND, 0);

        long intendedTime = firingCal.getTimeInMillis();
        long currentTime = currentCal.getTimeInMillis();

        if (intendedTime >= currentTime) {

            WakeLocker.acquire(getApplicationContext());

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, intendedTime,
                    AlarmManager.INTERVAL_DAY, pendingIntent);

            WakeLocker.release();

        } else {

            WakeLocker.acquire(getApplicationContext());

            firingCal.add(Calendar.DAY_OF_MONTH, 1);
            intendedTime = firingCal.getTimeInMillis();

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, intendedTime,
                    AlarmManager.INTERVAL_DAY, pendingIntent);

            WakeLocker.release();
        }
+3
source share
1 answer

The code seems wonderful. If the target version is 19,

Note:

API 19, . , , , . , targetSdkVersion , API 19, - , , .

: http://developer.android.com/reference/android/app/AlarmManager.html#setRepeating (int, long, long, android.app.PendingIntent)

:

API 19, , , : , . , "" , , "" . , , , .

, . , , . , API, ; . setWindow (int, long, long, PendingIntent) setExact (int, long, PendingIntent).

, targetSdkVersion API 19 : .

: http://developer.android.com/reference/android/app/AlarmManager.html#set (int, long, android.app.PendingIntent)

, , .

+3

All Articles