BroadcastReceiver的VS服务 [英] BroadcastReceiver vs Service

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

问题描述

那么,在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点吃   早餐)的数据库,并建立了AlarmManager显示   通知有关事件。

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为可能的,因为(从的 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.

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

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