Alarm Is Not Working In Android When The Device Is Off And On Again
I have set the alarm to remind me in android it is working when the device is on. But when i switch off the device and again on that reminder alarm is not working. Can you guys ple
Solution 1:
Alarms will be cleared on reboot.
What you can do is
- persist alarm information in a db table
- register for the
REBOOT_COMPLETED
-Event - On reboot, start a background thread the re-registers alarm. Make sure that you compute the alarm times correctly.
See API: "Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted." - http://developer.android.com/reference/android/app/AlarmManager.html
Solution 2:
Create a class OnBootReceiver
publicclassOnBootReceiverextendsBroadcastReceiver {
@OverridepublicvoidonReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
mgr.setRepeating(AlarmManager.RTC_WAKEUP,
SystemClock.currentThreadTimeMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES,
pi);
}
}
inside manifest
<receiverandroid:name=".OnBootReceiver" ><intent-filter><actionandroid:name="android.intent.action.BOOT_COMPLETED" /></intent-filter></receiver>
inside your activity
sendBroadcast(newIntent(this, OnBootReceiver.class));
Post a Comment for "Alarm Is Not Working In Android When The Device Is Off And On Again"