BroadcastReceiver的VS服务BroadcastReceiver、VS

由网友(一炮到天亮)分享简介:那么,在Android中,什么是BroadcastReceiver的和调用另一个在BroadcastReceiver的服务 做的事情有什么区别?我觉得他们都在后台运行,对吧?Well, in android, what is the difference between doing something in broa...

那么,在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.

阅读全文

相关推荐

最新文章