Android Background Service vs AlarmManager

依然范特西╮ 提交于 2019-12-05 08:24:19
Cool Java guy מוחמד

AlarmManager schedule the intents. Your service can crash and be removed if memory is not available. But with AlarmManager you can invoke your specific service at a scheduled time. In your context, AlarmManager is a better option than a running service.

Hope it will help you.

With the help of the AlarmManager you can schedule intents. Your service or a BroadcastReceiver can listen to these scheduled intents and perform tasks at the given time. You can not only use the AlarmManager to implement program logic.

You can use the AlarmManager to dispatch an Intent every 15 minutes with an action for A, one every hour for B and so on. Either your modules are implement as independent services or you decide on the intent action what to do.

Please keep also in mind that long operations should not be performed in a BroadcastReceiver.

There's a very good analysis on this new blog post: https://android-developers.googleblog.com/2018/10/modern-background-execution-in-android.html?linkId=58286424

For sync on regular basis you might end up using WorkManager, started on specific time or when triggered by a push message (FCM)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!