Android - Start an IntentService on a specific day/time each week - android

I'm working on an app that has an IntentService that shows a Notification with showtimes for a local venue. I want the IntentService to be called every Fri at 5am or at boot on Friday morning.
What would be the best way to do this?
Right now I'm thinking of having a parent IntentService that will start at each boot and check what day it is and run the child service accordingly, but I don't know how to deal with a scenario where the user doesn't reboot.
Also, how would I run just the IntentService at boot and not the entire GUI?
Thank you

You can use the AlarmManager and use the setRepeating() method to set an Alarm that goes off every week at the same time.
Your booting requirement is probably not worth the effort, as very very few people reboot their mobile devices often. I've personally gone months without turning my phone off.
However, you don't need a parent service. You can do the checking of the day when the child service first starts up, and have it kill itself if its not Friday.

Related

Is there a maximum limit time for functions in android alarm manager?

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.

How to make android service run every day once

I have a service that runs well but when phone goes to deep sleep , the service stop working .
I want to make use of some android class that makes the service to run everyday
at specific time ,??
i have tried wakelock but it drains the battery very fast for 24/24 cpu on
Any HELP ??
In case this becomes a bigger discussion then our comments. I'll list my answer here.
So your goal is to schedule a job with the alarm manager. Just make yourself a broadcast receiver class and register it on your app's startup. Then you will get code to run on each received notification.
If you need your service to run one time use an IntentService for efficiency instead of regular service.
Also, if you need to make sure it starts automatically then you should register for receiving of phone boot so that you can start your scheduled job again.
The link example:
Schedule a TimerTask at specific time once per day in a service in android
Better solution: you can use any of them alarm manager/jobscheduler/GCMNetworkManager
Create a alarm with looping every 24 hr interval.
That's all you need.
PS: Service will drain your battery.

Android - Service, Boot and check time

I have an android app, and I want that the user can decide when (day,hour,and minute) to do something.
So, I have to:
1) start a service when the android phone boots and when the user runs the app (for example after the installation)
2) check (how? how many often?) if the current time is the time choosed by the user
3) run a method if the time is right.
I searched a lot, and I'm a bit confusing...
I found that I have to use a BroadcastReceiver to check when the phone boots,then start an IntentService to have a background process that's check if the time is a "choosen time" and then call the method.
Am I right?
But how do I check the time? How many often should I do that?
You're right. You can use a BroadcastReceiver to check for boot. As for the chosen time, I recommend that you use the AlarmManager class to have your Service run at a particular time or interval.
ref: http://developer.android.com/reference/android/app/AlarmManager.html

AlarmManager Dilemma for Android

I want to set a repeating alarm monthly; but my app resets the alarm everytime it boots up. So is it bad practice to do it this way rather than setting a repeating alarm?
(The Alarm is set for a specific day of the month. (e.g. The 8th, 16th, 21st, etc). So if it is past that day, it simply +1's on the total the current month.)
I also run a service on boot up to set any alarms so even if they don't go into the app for a month, it will be reset again.
Again, is this the best way of doing this or is this bad practice?
So is it bad practice to do it this way rather than setting a repeating alarm?
If it works for you, it is probably fine.
I also run a service on boot up to set any alarms so even if they don't go into the app for a month, it will be reset again.
That is a little odd. Getting control at boot time to re-establish alarms is fine, but you should not need a service for that.

Run Command/Service on first occasion of day

I'm writing a simple Widget for Android which displays information which changes for every day. So the widget needs to be refreshed on midnight. The whole refreshing is implemented as a service and runs nicely, the problem is the invocation:
The only solution I found is to use the AlarmManager to a add an exact reoccurring timer on midnight each day. Then aquire a partial Wake-Lock, to make sure the device stays awake and run the code. This should work as expected but due to the usage of the wake lock, I am waking the device, so I am searching for a slimmer version:
There is no need to wake the device up on exact midnight, it is enough if I receive a timer event the first time the Device is up again on a new day. If the device is sleeping, nobody can look on the widget, so it is ok if the widget updates whenever the device is switched on again.
In other words: How do I run a service on the first moment of a day when the device is not sleeping, thus preventing a wakeup? I still need the device to stay awake than for period of time.
How can this bis done?
You can tell the AlarmManager to delay your invocation until the device wakes up anyway.
Then don't use a WakeLock in the.

Categories

Resources