I am working on one android application which allows user to set reminder for specific task or work. and i have created reminder in android using alarm manager. But my problem is when user move to some other time zone how can i change reminder time as per new time zone ?
2nd problem is if user have set reminder for two task at same time which one will get canceled by system ?
As android doesn't provide id for reminder.
I have already checked link1, link2 questions on SO but it is not valid for me in my 2nd case.
You should not to do that becouse you set it up in abcolute unix time value right?
It means that the same absolute time event will happens in the same moment in every time zone
P.S to cancele alarm you should use the same Intent as you use whent setup alarm. It just override previous alarm by new one. In my application i use only one alarm for all events, and i invalidate it value every time and set it up to earliest event time
I have a broadcast receiver that receives event when user manually changes Date . But I am unable to find what was the previous date he changed. Example- If date was 5-June-2014 and he changed it to 01-June-2014. I want to know the previous date that is 5-june-2014. Please help
You could register ACTION_TIME_TICK and record the current date every minute.
I am developing an application for a certain event like a count down.
In the foreground of the app I show the days, hours, minutes and seconds left till the event date/time with handler.
However, I'd like to be able to detect start of new day (when app is in background) and show a notification in the status bar like '29 days left'. I want to receive this event whenever the system date automatically changes to new day (23:59 -> 00:00) everyday until the end date of my event.
Having said all this, how can I achieve this with the AlarmManager (or any other way)?
I know how to set up broadcast receivers, I just don't know how to schedule the event to occur precisely when a new day has come.
I would consider using Joda Time, and use the withTimeAtStartOfDay method to get the next alarm.
I want to do some thing on changing date format of android Device.
But I do't find any broadcast action or any method for achieving it.
Create a content observer and listen to changes to Settings.System.DATE_FORMAT
I am building a reminder application where the user enters an event into an SQLite DB. The main screen lists the title of each reminder and clicking an item shows the details of it. All of this works fine.
Now I want to allow the user to set up notifications for each item, being given an option to set a reminder for 15 mins, 30 mins, or 1hr before the event is scheduled.
I have no clue how to go about this and can't find any good tutorial on it. Can anyone give me some idea as to how I might implement this?
Thanks!
Use the AlaramManager to fire a broadcast that will tell your app to show a notification to the user about the event.
Here is an example of using it: Alarm Manager Example
Once you get the date of the event from the database, it's as easy as any other notification, just keep in mind that you'd subtract the amount of time (the 15,30,60 minutes) to the date.
Timer timer = new Timer();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm");
Date date = formatter.parse("11/08/2012 16:39");
timer.schedule(timerTask, date);
This will schedule the event to the event time, and I'm understanding you want a reminder before the event actually happens. To do this you can create a calendar object to modify the date in the means you need. Remember to remove the previous schedule or you will be left with two reminders (one at the time, and one as a reminder).
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MINUTE, -15);//Or whatever
//Then schedule it.
time.schedule(timerTask,cal.getTime());
Both approaches are using the variable timerTask which could be something like this, involving the createNotification method call that will in fact create the pending notification.
TimerTask timerTask = new TimerTask(){
#Override
public void run(){
createNotification(title, text, tickerText, millisec);
}
};
There is a potential issue with this thou. If the application is closed, I believe the timer dies with it, so depending on the nature of your application you may want to use the AlarmManager as others have suggested.
You'll use the AlarmManager to set the action to be triggered on the specific date/time. (there're A LOT of tutorials on how to use the AlarmManager)
The alarm manager event always triggers a PendingIntent. From this intent you can either make a broadcast or start a service. (you'll have to create a broadcast receiver or a service)
Then on the broadcast receiver or service you build up and show the notification.
I suggest the broadcast receiver route, it's cleaner and more seamless.
you might also to have a broadcast receiver for onBoot events to re-schedule the events on the alarm manager case the user reboots the device.