Repeating alarm stops working

78 views Asked by At

I am using the alarm service for do some task daily at the midnight but today it stop working. I have check and finds that alarm service is not firing up. I am not able to figure out what is the problem.

AlarmManager alarmManager=(AlarmManager) getSystemService(ALARM_SERVICE);

        Intent alarmIntent=new Intent(context,UpdateTables.class);

        PendingIntent pendingIntent=PendingIntent.getBroadcast(context,0,alarmIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        alarmManager.cancel(pendingIntent);

        Calendar alarmStartTime = Calendar.getInstance();

        alarmStartTime.setTimeInMillis(System.currentTimeMillis());

        //midnight
        alarmStartTime.set(Calendar.HOUR_OF_DAY, 15);
        alarmStartTime.set(Calendar.MINUTE, 12);
        alarmStartTime.set(Calendar.SECOND, 0);


        if(Calendar.getInstance().getTimeInMillis()>alarmStartTime.getTimeInMillis())
        {
            alarmStartTime.add(Calendar.DATE,1);
        }

        Log.i("TIME IS ",Long.toString(alarmStartTime.getTimeInMillis()));


        System.out.println("Updating table time "+alarmStartTime);
        System.out.println("Time in millseconds "+alarmStartTime.getTimeInMillis());


        alarmManager.setInexactRepeating(AlarmManager.RTC,alarmStartTime.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);

in the manifest file.

<receiver android:name=".UpdateTables"
            android:enabled="true"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>

        </receiver>
0

There are 0 answers