0

I've made a program, which uses broadcastreceiver to create an alarm (which is activated after several days).

When the time comes, it is supposed to play a notification.

I've tried setting the time to few minutes, hours and the notification always plays.

However in real life testing when the time was over one day the notification doesn't work.

Is there a limit to which Broadcast receivers can be set to in the future?

Here is my code: [http://pastebin.com/JnxVExtK]

Let's say today is Sunday 5:00. If I set the alarm at Sunday 7:09 - It will ring.

But if I set the alarm for Wednesday at 3:00 - it won't work.

And obviously I cannot set the emulator for such long period.

I've been trying the program on my tablet and there too the notification fails to show up if the alarm is set to ring after few days.

Bilbo Baggins
  • 3,644
  • 8
  • 40
  • 64
  • Have you added timing information correctly ? check this too http://stackoverflow.com/questions/5770219/how-to-set-the-calendar-in-android-for-particular-hour – Chetan Apr 01 '13 at 12:32
  • try putting logs and change the timing on your own to test – Chetan Apr 01 '13 at 12:32
  • The problem here is u cant check it suddenly ,waitng for each output a day.,if its playing for minutes and hours it must play for day ,theres no time limitation for that,Post your code for notification – Viswanath Lekshmanan Apr 01 '13 at 12:56
  • @Chetan I've added my code. In both cases I'm only changing the time, my code remains same. I'm inputting the values for year, month, date, etc... Can restarting the device, flush out existing broadcast alarms? – Bilbo Baggins Apr 01 '13 at 13:56
  • @Arju I've added my code. – Bilbo Baggins Apr 01 '13 at 13:57
  • @PriteshDesai : Test it whether it works when your phone is restarted. – Chetan Apr 02 '13 at 05:47
  • @PriteshDesai : http://stackoverflow.com/questions/9683201/broadcastreceiver-is-not-working – Chetan Apr 02 '13 at 05:50
  • @PriteshDesai: look at this too http://android-developers.blogspot.kr/2007/11/stitch-in-time.html – Chetan Apr 02 '13 at 06:19

1 Answers1

0

fallow the two steps and schedule the task perfectly

1.create date object

Date dateobj=new Date(year-1900,month,day,hour,min);    

year - scheduling Year month-scheduling month(0-11) day-scheduling
day (1-30) hour scheduling hour (24 hrs format )(0-24) min
scheduling min 0-59


2. set the alarm to dateobj.getTime() its returns milli seconds 

alarmManager.set(AlarmManager.RTC_WAKEUP, dateobj.getTime(),
pendingIntent);
srinivas
  • 163
  • 9
  • I've added my code. Please take a look. It seems to work fine for alarms set few hrs from the current time. But fails if the time is set few days from now. – Bilbo Baggins Apr 01 '13 at 13:58
  • use the Date object for future schedules purpose instead calender and date class will give 100% success.i already developed in my old project.we implemented weekly,monthly, daily future also. – srinivas Apr 01 '13 at 14:41
  • Does it really make any difference? Do you have any reference? – Bilbo Baggins Apr 01 '13 at 15:28
  • for scheduling date class is better option and check the below link http://stackoverflow.com/questions/1404210/java-date-vs-calendar – srinivas Apr 01 '13 at 15:43