1

Hi I am developing a application in which i am using AlarmManager

Problem

When i set pending Intent using Alarm manager on perticular date and time its work fine but suppose i set alarm time on date 30-05-2011 and time 10:00 AM and suppose current time is date 30-05-2011 and time 09:50 AM and now after creating pending intent i switched off my device and after 10:01 AM i starts my device at that time i expect notification for 10:00 AM alarm but i am not getting it Any idea how i can get notification After switch on my mobile

Dharmendra
  • 33,296
  • 22
  • 86
  • 129

2 Answers2

2

Through AlarmManager, you can only wake up your device when it is sleeping.

To do that use setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation) or set(...)

with RTC_WAKEUP or ELAPSED_REALTIME_WAKEUP

But it doesn't work with a device at off. So you should consider having your alarms in a database, along with the last time your app was on, and count the alarms you missed since last time you were up.

Regards, Stéphane

Snicolas
  • 37,840
  • 15
  • 114
  • 173
1

If you read the AlarmManager API doc page:

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.

As an alternative, you can register a broadcast receiver for the intent android.intent.action.BOOT_COMPLETED and check your SharedPreferences if you need to perform an action.

See this question for details about the broadcast: Trying to start a service on boot on Android

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • is there any way to get notification which are passed on device off time on startup ? – Dharmendra May 30 '11 at 05:16
  • No. The way to do it is as I said above. The app receives the notification that the phone booted up and then the app itself has to check the status. It can easily done with SharedPreferences. – Aleadam May 30 '11 at 05:21