SERVICE FOR NOTIFICATIONS - android

Can anyone tell me how to do a service that will generate a notification every day at a certain time (for example at noon)?
Or rather, do I need a service to do this?
Naturally I am talking about Android programming

In Android, You can implement with options:
AlarmManager
Schedule job
Server schedule job
Or something other options,...

Related

Create Reminder Notification for Android

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.

How to program notifications like google keep?

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

Which approach to use to make a daily notification?

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

scheduled notification

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?

Best way to have an Android app poll periodically in the background

Take the Gmail app as an example. Whether the phone is on or not, it polls every 10 minutes or so to download new emails which may have arrived since you last checked.
I know how to create a new service and bind to it. But I can see a few ways to accomplish this:
Bind once, and have the service run in an infinite loop, sleeping for 10 minutes between each loop
Bind and unbind right when it's done, scheduling the next bind somehow in 10 minutes
Using the AlarmManager class to schedule future polls
What are the trade offs? How does the Gmail app accomplish it?
Thanks!
Gmail app uses pushing, not polling. I suggest using this technique instead, polling is a battery killer in mobile devices.
To implement pushing, take a look at C2DM.
If you still want to poll, the recommended way would be to set up a periodic alarm in the AlarmManager.
UPDATE: Google has deprecated C2DM and replaced it with Google Cloud Messaging (GCM)
UPDATE: Google has deprecated GCM and replaced it with
Firebase Cloud Messaging (FCM)
For a continuous, but not intensive poll like the one you comment (in the range of minutes between polls), I would implement it with AlarmManager. That way you make sure the phone wakes up to poll without the need for a wakelock, which would destroy your battery. As CommonsWare pointed out, you will still need to implement a wakelock for the time your code is executing, but you can release it as soon as the code is done, avoiding keeping the phone on while just waiting. See his comment for an example on how to implement it.
I would use a Service if, instead, you need faster polls during a shorter period of time (seconds between each poll), since setting alarms does not make sense to such short periods, and the battery would drain anyway.

Categories

Resources