0

well in my app I want the user to get notifications depending on the time is it. So, it must check all the time current date and time, and giving notification for the upcoming event.

I have found tutorials like these: tutorial 1

but all of these are triggered after pressing a button and setting something like an alarm.

But I want my app to be able to do that "checks" all the time. So do I have to use a service or is there any other way? I have never used services before that's why I am not sure if this is what I need or not.

EDIT: I cam wondering if using alarm. My problem in that case is that I do not any interference from the user. I mean he must not press a button to set the alarm but the app has to worki like this: first alarm at: sunday 9 october 11:00 next at: same day 18:00 next: 10 sept 07:00 and so on..

ghostrider
  • 5,131
  • 14
  • 72
  • 120

1 Answers1

0

If you don't need to check notifications when the app isn't running, you can just use Handler.postDelayed to have your code run after some time has passed.

If you want to check notifications in the background even if your app isn't running, you'll need to use an alarm. Check the AlarmManager out.

zmbq
  • 38,013
  • 14
  • 101
  • 171
  • well think that I want the user to be notified for a specific event at a given date and time. So I want when that time comes, to push a notification. and then wait for the next one. user will not set anything, press a button or something like this. – ghostrider Sep 09 '12 at 09:10
  • Yes, but will he need to run the app at that time or not? – zmbq Sep 09 '12 at 09:13
  • not necessarily. I only want to provide him with the notification of upcoming events. So he will not be running that app at that time. – ghostrider Sep 09 '12 at 09:32
  • I have done this but it runs only for the first notification. then the user must somehow "enable" the alarm. i want the app to check current date and time all the time and depending on the time, user will be notified. I can provide my code if you wish. Thanks for your time. – ghostrider Sep 09 '12 at 10:12
  • 1
    Set a repeating alarm: http://stackoverflow.com/questions/4430849/how-to-set-recurring-alarmmanager-to-execute-code-daily – zmbq Sep 09 '12 at 10:25