-1

I have two times and each day these times are different from the previous day for example reminder1-day1: 5:30 reminder1-day2: 5:35

I'm getting the time from the internet with json objects... what I need is to trigger a notification when the system's clock reaches the reminder's time, what I've already done is an actvity containing an alrm manger that takes the time of this reminder and on broad cast receiver it creates a notification; but this isn't a good solution because I can't do a repeating alarm because each day I have different times... and I can't call the same alarm method on broadcast receiver because I would need to create the whole activity again to take all the variable again because they won't be there anymore...

so is there a way to create a service that will work all the time even when the phone is rebooted it will continue its work and will compare the system's time and the reminder's time and will trigger the notification when the two times are equal or is there another solution? thanks.

Edit

public void scheduleAlarm()
        {
            Long time=calendar.getTimeInMillis()+5*60*1000;
         //other lines to get the real time..  





           Intent intentAlarm = new Intent(this, TimeAlarm.class);


            AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);


           alarmManager.set(AlarmManager.RTC_WAKEUP,time, PendingIntent.getBroadcast(this,1,  intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));

        }
User
  • 509
  • 2
  • 8
  • 23

2 Answers2

0

There are another approach you can go on like getting the new time, unregister and register your schedule when the pending alarm is fired, but also is possible the solution that involve a use service with a small and carefully configuration to allow your service behave well depending on system status.

Jans
  • 11,064
  • 3
  • 37
  • 45
  • please can you give me more information or a link to follow.. thanks. – User Oct 09 '13 at 17:22
  • For well configuration of [`Android Services`](http://developer.android.com/guide/components/services.html#ExtendingService) and for links relate of registering and unregister [`AlarmManager`](http://stackoverflow.com/questions/4459058/alarm-manager-example) – Jans Oct 09 '13 at 17:28
0

GOt it needed to write my alarm method in a service and get all the needed variables in that service once the alarm is triggered will be caught by the intent broadcast receiver which will create a notification and get the alarm to work once again...

User
  • 509
  • 2
  • 8
  • 23