androidalarmmanageralarmandroid-alarmsrepeatingalarm

alarm not working when app is closed


Alarm is working fine when I am working with the emulator. But not working when i try on actual devices.

Output when app is open.

RTC #8: Alarm{2c1fc9e type 1 when 1486492260454 user.com.hlthee}
    tag=*alarm*:user.com.hlthee/.UpdateTables
    type=1 whenElapsed=+22h43m2s644ms when=2017-02-08 00:01:00
    window=-1 repeatInterval=86400000 count=0
    operation=PendingIntent{7c4e37f: PendingIntentRecord{3f5fbf4c user.com.hlthee broadcastIntent}}

But when I closed the app then this entry removed.Why?? That's why Alarm is not ringing.

Alarm receiver broadcaster 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>

Please don't say use service and register the receiver there. I think I am registering the receiver in manifest it will works. And also alarm in working fine in emulator. Not able to solve this issue from last 3 days. Any helps will be helpfull.

I have tried these method also:

  1. using wakefullBroadcastReceiver instead of BroadcastReceiver
  2. use setAlarmclock instead of setExact.

Anyone also facing the same problem.


Solution

  • Do implement onTaskRemoved and onDestroy

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        //Set what to do when task is removed
        super.onTaskRemoved(rootIntent);
    }
    
    @Override
    public void onDestroy() {
        //What to do when service i destroyed
        super.onDestroy();
    }