Backgroud
I am using AlarmManager and JobScheduler(=> API 21) to generate Notification at 11 am in the morning.
Issue
Suppose my device is turned off at 11 am. So Alarm will not go off and Notification is not generated for today. Now, when it will reboot. the alarm is set again for 11 am of next day using BroadCastReceiver on action.BOOT_COMPLETED.
I have explored Job Scheduler a bit and setPeriodic(ms) function is used to set a periodic job but does not allow to schedule a job at specific time.
(Google -> define schedule -> arrange or plan (an event) to take place at a particular time.).
Any pointer to workarounds to this use case. I would prefer native solution, though.
Related
I have an app that runs entirely local/offline, and at midnight (using android_alarm_manager and flutter_local_notifications) it does some processing to create and schedule user notifications based on the actual local data of the user and recreate the alarm at midnight, the problem is that after a few days these background processes just stop, if I put it to run every minute it works great when I'm using the device, but when running at midnight its only works on the first days, I even put some logs to see if any errors happened (creating logs in cache and reading them later), but after a few days the app just stops logging too. I think this is caused by android killing the services when it is taking a bit long, but I don't really sure, and if it is, there is another way to make background services on android or the best way is to put my app and user data online and with firebase create and send notifications?
I think I solved the problem, to solve this I used the same packages and the Workmanager, so with AlarmManager I can schedule a alarm to start at midnight that generates and start a periodic work (24 hours) to based on the user data send notifications to the user.
I think this one is a better approach because even android says that WorkManager is the right tool to do background work and alarmmanager is for alarms only.
I am a beginner
i want to Give Notification on specific day in long time example i want to set Notification for 6 months longer Should I use ŮŽAlarm Manager or countdown timer , Or I can do it by Conditions and joda-time Component?
timer is not a good idea because it may kill by os but you can use the alarmManager or workManager but you should also listing on device boot complete and register your task again to alarmManager
here is a good tutorial for using alarm manager :
https://en.proft.me/2017/05/7/scheduling-operations-alarmmanager-android/
I am using AlarmManager in our app to set alarms that are set at specific date and time. Now recently few users of our app are complaining that these alarms are not popping up. Also, in Android O guidelines, it is mentioned that app should not run any background service and instead should switch to Firebase JobDispatcher. I have following 2 questions
In our app, we do not do any background task except to show notification to user at the specified time and date. Even in this case, should we switch to Firebase Jobdispatcher?
In case we do need to switch to JobDispatcher, how can the Job be set to run at exactly specific date and time?
Because you're not doing any background tasks like network requests or long running CPU operations, I think you should continue using Alarm Manager.
Now recently few users of our app are complaining that these alarms are not popping up.
This is because when doze mode triggers, it is not guaranteed that your alarms will be triggered(see this).
What you can do is use setAndAllowWhileIdle() or setExactAndAllowWhileIdle() methods from AlarmManager class as per your requirement for API level >= 23.
According to the documentation these are appropriate for notification purposes.
setAndAllowWhileIdle() documentation:
Like set(int, long, PendingIntent), but this alarm will be allowed to
execute even when the system is in low-power idle modes. This type of
alarm must only be used for situations where it is actually required
that the alarm go off while in idle -- a reasonable example would be
for a calendar notification that should make a sound so the user is
aware of it. When the alarm is dispatched, the app will also be added
to the system's temporary whitelist for approximately 10 seconds to
allow that application to acquire further wake locks in which to
complete its work.
Short version: Alarm Managers no longer work in the background in Android 8 (Oreo), Android people are saying to use Job Scheduler as the alternative, but the job scheduler doesn't allow specific times of the day like Alarm Manager did so well.
Longer version: I have a "reminder" notification that goes off at a specific time of day set by the user. Up to this point, I've used an alarm manager to post the notification at the set time. This sends the user a notification to the user even if the app is in the background. But in Android Oreo / 8.0, this isn't allowed anymore. Most background services, receivers, etc. are fairly limited. I've set up a job scheduler, but doesn't allow for an exact time. Periodic settings in the job scheduler cannot be set ahead to a specific time. So despite Android's claims that job scheduler is the intended replacement for alarm manager, it doesn't seem to do one of the key things people use it for, setting at a specific time of the day. Does anyone know of a way to do this in Android Oreo in a way that it works even when the app is in the background?
I've tried sync adapters (need the alarm manager for that too!), handlers (nothing for a specific time), playing around with the different settings for the job service (periodic, minimumLatency, etc.), resetting the notification after the last one finished (can't do that in the background either!), and still haven't found a valid solution.
Is there anything that works like the job scheduler (i.e. Android 8/Oreo lets you run in the background, but that lets you schedule an exact time of the day, on a daily basis?
Alarm Managers no longer work in the background in Android 8 (Oreo)
I am not aware of anything regarding AlarmManager that changed in Android 8.0. Feel free to point to documentation or an issue tracker entry to validate your claim. Or, file your own issue with a reproducible test case.
But in Android Oreo / 8.0, this isn't allowed anymore.
Sure it is, at least as well as it worked in Android 6.0 through 7.1. Doze mode and app standby have screwed with AlarmManager, but that's not new to Android 8.0.
Most background services, receivers, etc. are fairly limited.
They can still raise a Notification, which is what your question indicates that you want to do.
Does anyone know of a way to do this in Android Oreo in a way that it works even when the app is in the background?
Use AlarmManager. Since you are writing what amounts to an alarm clock app, use setAlarmClock().
one solution i can suggest may be solved your problem.
you should start job schedule 15 minute repeater mode and call every minute one broadcast where you can check this current time is your specific time of day or not.
if yes then send notification.
I'm learning Android and want to write some kind of count-down timer application, so I get a ring-tone after certain minutes are elapsed. The timer also should work if the user has closed the application or switched to another one. If my application is running, it should be able to display the remaining time.
I've tried with CountDownTimer, but this seems only to work when the phone is activated, but not like the alarms which could ring you up at the morning. What other similar API alternatives are there to activate the device if the time is elapsed?
You can use AlarmManager for this purpose.
count-down and alarm are two very different things (even thou both count time).
Count-down you probably want to run a service and put a notification with the flag ongoing = true updating the value of the time.
Alarm you want to use the AlarmManager (as pointed out by #PgmFreek) that you can schedule a specific time that the system will call an Intent for you.