Android的广播接收器和Activity.onPause() [英] Android BroadcastReceiver and Activity.onPause()

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

问题描述

有关广播接收器文档说

如果您在注册Activity.onResume一个接收器()实现,
      你应该注销它Activity.onPause()。
      (暂停时您将不会收到意图,这将减少不必要的
      系统开销)。

If registering a receiver in your Activity.onResume() implementation, you should unregister it in Activity.onPause(). (You won't receive intents when paused, and this will cut down on unnecessary system overhead).

我提出,具有内的BroadcastReceiver用于更新A 1接口时,一个服务S1使得sendBroadcast活性A1的一个例子。 S1花费约8秒完成。

I made an example of Activity A1 that has an inner BroadcastReceiver that updates A1 interface when a Service S1 makes a sendBroadcast. S1 spends around 8 seconds to finish.

在运行A1和击球作出A1调用的onPause,它仍然会接收来自sendBroadcast的意图,并更新界面home键,我失去的东西或文档是错误的?结果
谢谢

When running A1 and hitting the home button for making A1 call onPause, "it still receives the intent from sendBroadcast" and updates the interface, am I missing something or the documentation is wrong?
Thanks

推荐答案

的意思是说文件,如果在未注册的onPause(),那么你就不会暂停时接收广播意图。如果你没有注册的话,你会继续接收广播意图。您未注册在的onDestroy(),但是当home键是pressed唯一的onStop()被调用和的onDestroy()将不会被调用。因此,你不断地接收广播。

The document meant to say that if you unregistered in onPause() then you won't receive broadcast intents when paused. If you do not unregistered then you would continue to receive broadcast intents. You unregistered in onDestroy(), but when the home key is pressed only onStop() is called and onDestroy() will not be called. Thus you continue to receive broadcast.

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

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