I'm trying to add alarm feature to my app or reminder with notification and I found a tutorial uses Alarmmanger for that but I wonder if is a new way is better for that, is workmanger good over alarmmanger?
the function of the app gonna be like that:
user add a note with time and date and choose which he prefers to remember the note as alarm or reminder
if it is alarm, the phone gets and alarm notification with ring sound and dismiss button on notification and if he clicks on the notification he get back to the app with alarm screen and he able to dismiss it or postpone
if it is a reminder, the phone gets a simple notification with sound with dismiss button in the notification.
so what is the best practice to do that, and it would be favor if you provide with me with tutorials about how to implement that
https://developer.android.com/guide/background#recommended-solutions
Per your description, it seems you fall under:
Exact tasks
A task that needs to be executed at an exact point in time can use AlarmManager.
To learn more about AlarmManager, see Schedule repeating alarms.
Related
I know how to create scheduled notification in Android by using alarm service but what I want to do now is to create notification in more frequent way.
For example, I want to push notification for 8 hours at the interval of 20 mins. In this case, is it efficient to use alarm service or timertask will be the better choice?
No matter which method, I wish to able to cancel it in the halfway. Thanks.
Timertask starts new thread and works in it. So if your app will work in background and your app will be closed by android, you won't receive any notification. AlarmManager provides access to the system alarm services. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. (link). So it will start your app even if it was closed. And you have to understand how you app will work with this notifications. If it works only while user works in app, you can use timertask, but if it has to work in background(for example you will receive notification even if user doesn't work with a phone/tablet), it will be better use alarmanager. Hope it helps.
I need notifications like Google keep which run at a specified time even when app is not running. I mean reminder notifications, which remind according to the time set. There are lot of applications which do this like ColorNote.
I know how to create a notification. I don't know how to schedule it a later time , even when app is not running.
You need to create a Service to keep going while your app is not running, and set an alarm using AlarmManager to schedule your action.
Read about the right way to do repeating alarms here:
https://developer.android.com/training/scheduling/alarms.html
And about Services here:
http://developer.android.com/guide/components/services.html
I am developing a birthday reminder app which will notify user on specified date the birthday event. I have googled web and found alarm manager in android to carry out my task.
But i just want to make sure is this the only way followed in making apps like reminder or we have some methods also
I checked this tutorial
Yes, Alarm Manager is what you want. Don't forget to register a boot receiver to set your alarms back up after a reboot.
Also no this is not the only way. but other ways are more complicated still, and potential less reliable. For example you could save the date/time to a server, and have it send a push notification to set off the alarm at the appropriate time.
However Alarm Manger was intended for things like this, so best use it. There is always more than one way to do things, and any clever person can come up with a hackish way to do something. But Alarm Manager is easy, and standardized.
Hi I need to set AlarmManager to run a reminder for me to take medication. I need to repeat it by custom amount of days and custom amount of times to take in the day.
So is there an efficient way to set the AlarmManager or CommonsWare's Implementation of the AlarmManager to remind me "twice a day starting at 9AM for the next 5 days" to remind me to take medication? Pls advice and tnx in advance for any constructive help in sample code and in relevant tutorials.
I haven't looked into Mark's AlarmManager implementation, but there is no way, in general, to get the bare AlarmManager to do what you are trying to do. You can schedule a single alarm, at a specific time, or a repeating alarm, that repeats at fixed intervals. If you want something that handles complex schedules like the one you describe, you'll have to write or find code that does it.
You want to use a PendingIntent with the AlarmManager. The idea is to schedule the pendingIntent with the alarmManager, have that trigger an intentService or broadcast, setup another pendingIntent with the alarmManager for the next desired event. You want to keep in mind that you'll need the BOOT_RECEIVED permission in case the user reboots their device. I have complex scheduling in Audio Control and this is exactly what I do.
Here is a pretty decent tutorial of what I mean:
http://android-er.blogspot.com/2010/10/simple-example-of-alarm-service-using.html
You need to schedule an alarm to the next time you want to take the medicine - according to your algorithm (for example if its twice a day, and you got to the pending intent callback for the first time today, then schedule the next alarm to start after [6,7,8,9,10...] hours).
You will need to save both last time of the alarm launch and the user settings in shared prefs/file/DB.
You need to handle process down (android killed it or the device was rebooted). In the case of device reboot you should use the boot receiver to start your service, but you need to remember that from android 3.1 the user has to use at least one time the GUI in order for you to intercept the boot completed receiver. The boot completed receiver should look when was the last time that the alarm launched, and according to the user settings set the next alarm launch.
In the case of android killed your service, you will need to make research, i can't help here.
see example
Is there a way to send a notification to the user that app has been downloaded but a certain task from the app is not yet complete even after certain period - say a month. One way is a background service which should come alive every month in this case, check the app state (in sharedprefs) and then send a notification. Is there some other easier way in Android without writing custom service.
Here's how I would do it. Schedule an alarm using the AlarmManager to go off a month from today. That alarm can trigger some code inside of a Receiver or otherwise to check whether the said event has occured. If it hasn't, you can then show a Dialog or whatever.
In order to wake up your app after some amount of time (in your example a month) you're going to have to set an alarm. You can use AlarmManager for that. If all you're going to do is check SharedPreferences, you can do that in a broadcast receiver. You can send your notification there.