Repeating operation in Android without alarm manager - java

I created application for sending sms interval. I used AlarmManager, which worked good, however after few days of proper working (send SMS at established time). It starts sending at different time or desist.
As far as I know, this is often problem with AlarmManager.
Is there some trap with AM ? or maybe you know better solution, library for that type of problem?
Thanks in advance

if the interval of time for sending the email is more than 15 minutes, I suggest you to use JobScheduler. That work really good over all android versions. I mentioned more than 15 mins because JobScheduler only can schedule at least every 15 mins on android 7 and over.

JobScheduler is an option, but this is only available on Android API Level 21+ (Lollipop v5.0).
A better option is to use WorkManager, currently in beta, that provides the same functionality (and limits like the mentioned 15 minutes minimum interval) but down to API level 14.
You can find more information about WorkManager on this series of blogs and on the documentation.

Related

Using AlarmManager for periodic task Android

I am new to Android. I want to develop an app that is going to do something every 20 minutes: if the user is in the app, they just get a message, else, the app will set a dialog and if the user accepts that dialog, the app will open and the user will get that message.
I have searched how to do that and ended up using alarm manager and everything went fine. However, the question is that if using alarm manager is good for this situation. If not, why? And what is the solution? I had read somewhere that work manager is also good.
WorkManager will not be useful in a case like this when device enters Doze mode.
WorkManager adheres to power-saving features and best practices like Doze mode
I have seen that even after white listing the app, (removing from battery optimisation), if device is left unused, stationary, unplugged, WorkManager work is delayed until the next maintenance window, sometimes hours of delays.
AlarmManager can be used but documentation recommends
Exact alarms should only be used for user-facing features. Learn more about the acceptable use cases for setting an exact alarm.
FCM is another option that could be considered in doze mode.
Edit: WorkManager is definitely recommended for persistent onetime or periodic works which are not time sensitive, where combination of constraints can be applied.

How can I run background work like alarm on latest android phones

I have some task like medicine reminder. Everyday reminder schedule is stored in the SQLite database. Reminders are every day different.
For example
21.02.19 - 08:00, 12:00, 19:00
22.02.19 - 08:30, 12:30, 19:30
...
Minimum android 4.4 (Api 19)
Target android 9.0 (Api 28)
I read about WorkManager, JobScheduler, JobIntentService, FirebaseJobDispathcer, Alarm manager. There is a lot of API s to do that.
Firstly I tried to check time with interval every minute using alarm manager. But it is not working properly in latest android. There have background restrictions, Doze Mode and standby. Then I tried JobScheduler but it does not work devices under 21 API. And FirebaseJobDispatcher required google play service, it is not a good idea. Finally, I find WorkManager. But in workmanager and jobscheduler have minimum interval like 15 minutes.
How can I make background service to remind users in specific exact time every day? I am not using the internet, GPS, location. Only get time from SQLite and remind in exact time.
In a few months ago, I developed medicine reminder app too.
I use 'run the daily job in 0:00AM using android-job' methods to achieve this.
In DailyJob, we have this process.
Grab some time information in DB
Convert (desired time - now time) into milliseconds. if now time is 00:15AM and desire time is 07:00AM, it will be 24300000ms.
Run exact job with converted milliseconds in Step 2.
In Exact job, we display a notification to the user.
I can't attach code because of privacy, but you can achieve the same things.

Android - What is the best practice for background tasks?

my app lets user create scheduled task.
Example: Tomorow show this notification => this notification leads to this activity etc.
What is the best practice to do this? Do I need to use some background task manager? How can I do this so it will work even when App is not running?
Facebook is doing something similar, when it is not running it still checks web for useful info for you.
Can somebody point me to some tutorial or get me some example? Thank you
There are several solutions that are recommended by Android framework team
Firebase JobDispatcher
GCM Network Manager, codelab
Job Scheduler api 21+
For showing a notification at a known point in the future (either a specific time or X hours from now) use AlarmManager to set an alarm.
For getting notifications from a server, generally you'd use push messages from the server. Although polling the server on an alarm would also work.

AlarmManager effect on battery for an Alarm clock app

I want to built a alarm clock app for android
I'm using an AlarmManager that starts a service every 1 seconds to check system time.
now I have 3 question:
1- Is there an other way to check system time every 1 second? and what is the best way for this work?
2-what is this my way on battery charge? is it cause to reduce battery charge very faster?
3- what mechanism use the android alarm app for checking time?
please help me to built this app
thanks
Why don't you just use the AlarmManager functionality supplied by the OS, and not try and invent this yourself. Basically this allows you to make a call to a service at a predetermined time (probably ultimately what you want to do).
What you suggest would be very problematic for battery, and doesn't sound like a good approach.

Android: Update some weather Data from server every X hours

What is the best and most efficient way in android to schedule an update for some weather data from the server every X hours?
Thanks
Sam
If you are asking about scheduling system, a good way is using AlarmManager, which can wake up your activity even if it is not running.
Here is some info: http://developer.android.com/reference/android/app/AlarmManager.html
And here a nice example with Notification: http://android.arnodenhond.com/tutorials/alarm-notification
Register your app with AlarmManager.

Categories