BroadcastReceiver的和暂停活动 [英] Broadcastreceiver and Paused activity

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

问题描述

我在一个活动编程注册的广播接收器。它响应 PACKAGE_REMOVED 的意图,将触发当一个软件包被删除。

I have a broadcast receiver registered programatically in a activity. It responds to the PACKAGE_REMOVED intent, that fires when a package gets removed.

现在的问题是,它并没有得到这个消息。我想这是因为,当我离开这个活动,并移动到另一个活动卸载应用程序的意图被解雇了,所以原来的活动被暂停。 难道说暂停活动(其中接收器,未注销的的onPause )也暂停接收器?

The problem is, it doesn't get this message. I think this is due to that the intent is fired when I leave the activity and move to another activity to uninstall a app, so the original activity is paused. Could it be that a paused activity (where the receiver is not unregistered in onPause) also pauses the receiver?

推荐答案

当您在活动编程注册一个广播接收器,它不会广播活动时暂停。该BroadcastReceiver的文档不明确的,因为他们可能是在这一点上。他们建议在注销的onPause只是为了减少系统开销。

When you register a broadcast receiver programatically in an activity, it will NOT get broadcasts when the activity is paused. The BroadcastReceiver docs are not as clear as they could be on this point. They recommend unregistering on onPause solely to reduce system overhead.

如果您要接收的事件,即使你的活动是不是在前台,用的接收机元素。

If you want to receive events even when your activity is not in the foreground, register the receiver in your manifest using the receiver element.

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

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