广播接收器与服务 [英] BroadcastReceiver vs Service

查看:31
本文介绍了广播接收器与服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,在android中,在broadcastReceiver中做某事在broadcastReceiver中调用另一个服务有什么区别?我认为它们都在后台运行,对吗?

Well, in android, what is the difference between doing something in broadcastReceiver and calling another service in broadcastReceiver? I think they both run in background,right?

其实我要做的是:

在每天的特定时间,下载用户事件(例如:上午 9:00 吃早餐)从数据库,并设置报警管理器显示活动通知.

In certain time of everyday, download the user event(eg: 9:00 am eat breakfast) from database, and set up the AlarmManager to show notification about the event.

现在我设置了一个闹钟管理器来完成上述任务.我很困惑我应该直接在 BroadcastReceiver 中完成这个还是在 BroadcastReceiver 中调用服务来完成这个.

Now I set up a alarm manager to do the above task. And I am puzzled should I directly accomplish this in BroadcastReceiver or call service in BroadcastReceiver to accomplish this.

谢谢.

推荐答案

您应该尽可能在 BroadcastReceiver 中进行 LITTLE 处理,因为(引用自 Android 博客)

You should do as LITTLE processing in a BroadcastReceiver as possible because (quoting from the Android Blog)

在处理广播时,应用程序被赋予一组固定的完成其工作的时间(当前为 10 秒).如果没有在那段时间内完成,申请被认为是行为不端,其过程立即被抛入后台如果需要,状态将被杀死以获取内存.

When handling a broadcast, the application is given a fixed set of time (currently 10 seconds) in which to do its work. If it doesn't complete in that time, the application is considered to be misbehaving, and its process immediately tossed into the background state to be killed for memory if needed.

这篇关于广播接收器与服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆