I want my app to do is: Once a day check if the user have written a note, If not, add a notification to the statusbar, reminding the user to start the app, and write a note.
Can I use the alarm-manager or do I have to use a Service for this? Do anyone know where to find a good tutorial on this, or have some example code ?
Use AlarmManager. Permanently running a Service just for scheduling a regular task would be an overkill.
Have a look at this question, for example: AlarmManager Android Every Day
Related
I am writing a python app in kivy.
The idea is to allow the user to make notes of bookings for certain dates, and then the program should send them a notification on that day about the booking.
There's probably a simple way to do this, I am using plyer.
from plyer import notification
notification.notify(title="Kivy Notification",message="Plyer Up and Running!",app_name="Waentjies",app_icon="icon.png",timeout=10)
This works, I get a notification whenever I call that function, however, I can't find any way to send this notification while the app is not running, I do know that there are some other questions that seem to answer this question, but they don't, their simply to run a app in background, which I don't want to do, all I want is something like Clash of Clans notification when your troops are ready for battle, or Facebook's notification when somebody liked your post.
I think you should take a look at the Android AlarmManager. If this is what you need, here is an example for Kivy.
AlarmManager
This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. 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.
On Android, I'm not sure how I would implement it without a background service.
The thing with background services is they also get killed when the application that started the process gets killed.
I know 2-3 ways to prevent that on Android, I consider it hack, but maybe it's a feature.
One is to use the START_STICKY flag. It's implemented in python-for-android, but it seems broken to me.
Another one is to use the a recent feature, setAutoRestartService(). It will make the service restart itself gracefully/programmatically on kill.
Bonus way use a BroadcastReceiver, but this is not implemented in p4a.
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.
I have to develop android app which must schedule different notifications in a distinct date that is in the future. I have the idea to not schedule using AlarmManager in an Activity class for all notifications in the same time in my app but instead using a service in the app that can each 24h(= per day) verify if there is one or more than one notification to show today for the user of my app. My datas are many dates in the future that specify the time when the user must be notified. What is the best practice ? And you 're welcome if you have another kind of solution.
I don't think it's a good idea to implement a service for alarms like you describe. AlarmManager was made for this purpose. If you were to implement a service, first you would be taking resources 24/7, and the user isn't going to like that. Second, how are you going to notify the user if the device is asleep? It seems overly complicated. Is there a reason you don't want to use AlarmManager?
I'm implementing an background process that will update information my app uses.
I only want this process to update say once a day, if the process gets data newer than what it had before I want to present the user with a notification, exactly like twitter/gmail does.
I want the update process to run automatically, even when the main app is not open.
Is a Service the best way to go? I've been reading quite a bit about this, I figured a service running all the time for something that is only going to do work once a day seems a little overkill.
However I notice google run service for friendlocation and google+ services continuously on my nexus.
I've look into starting my service via the AlarmManager so its only started when required.
Some posts also suggest using the Handler class, I don't think this will work.
Just looking for the best practice here.
I figured a service running all the time for something that is only going to do work once a day seems a little overkill.
Absolutely.
I've look into starting my service via the AlarmManager so its only started when required.
This is the correct answer.
If you only want your code to be invoked if the device is on, implement an IntentService, do your work in its onHandleIntent(), and have AlarmManager start up the service on your desired schedule.
If you want your code to force the phone to wake up, you can do that, but you will need to use a _WAKEUP-style alarm, and you will probably want to look at my WakefulIntentService, designed to handle this pattern.
I want to write reminder. What i need to use? Make service app or just standart app runing in background or another way?
Thanks for replys!
What I really liked about this question is you asked about the idea for the app that you want to implement. You didn't ask for code.
I would suggest that you should make an app which should have a broadcast receiver, but still it should have service that runs in background.
The service will check the current time with your reminder time. A broadcast receiver is required to listen to startup broadcast, because you need to start your app as soon as your handset starts.
Have a look at this.
Have a look at the AlarmManager. It allows you to schedule your application to be run at some point in the future.