Cancel already set reminder and set new for new time zone - android

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

Related

Trigger an activity if the clock is match

I want to start an activity if the clock is 15.00. Is there any reference ?
Assuming i had running services in my background.
EDIT
I have value from database. Then the activity will trigger based on clock that i saved from database. So if the database has values like 01.00 , 13.00 , 22.30 then the activity will start when the phone clock match as that 3 value.
You can use an AlarmManager for that
This post will help you. Use AlarmManager to set a repeating alarm. The time can be set.
Android notification app not working properly

Android event that occurs on every start of new day until some end date

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.

Cancelling Alarms with PendingIntents

I am trying to cancel an alarm that was set last time my app was run. This alarm has a PendingIntent that was set with PendingIntent.getBroadcast and an inner Intent that contains some variables set by intent.putExtra. My question is this, I know that alarms can be canceled by calling alarmManager.cancel(pendingIntent) where pendingIntent is the same as the one used to set the alarm. But, if the variables placed into the intent are changed will the alarm still be canceled? For example, I set an alarm with intent.putExtra("Joe") where Joe is a contact name. Later my app is closed and when it is re-run I try and cancel the alarm for "Joe" but the user has changed the name of the contact to "Jones". Can I cancel the alarm without knowing the variables I put into the intent?
Thanks!
I think it should cancel the alaram anyway, even though some data is different. The cancel method says:
Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.
And filterEquals says:
Determine if two intents are the same for the purposes of intent resolution (filtering). That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.
Anyhow, I'd still test it myself.
According to this question (which references the documentation), anything you add using putExtra is not taken into account when checking if an intent is equal to another one.
It shouldn't matter if the extra data is changed.

Set android notifications from SQLite DB

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.

set an alarm to any date and time from datepicker dialog

I try to use datepicker to set the time, and I also built an alarm for that time I set, but the alarm always paly at current time instead of my set time, I don't know why, please help, thanks! here is my code:
You should remove this line:
alarmTime.setTimeInMillis(System.currentTimeMillis());
as it set the time of the calendar to current time.

Categories

Resources