其中,注册广播接收器的最佳实践? [英] best practice where to register broadcast receiver?

查看:112
本文介绍了其中,注册广播接收器的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里的'最好'注册一个接收器快速的意见的问题吗?在我的情况我服务的每个UI需要更新时间发送一个广播。

quick opinion question on where its 'best' to register a receiver? In my case my service sends a broadcast each time the UI needs updating.

选项,因为我理解他们
。表现
。在OnCreate
。 ONSTART
。 Onresume

Options as i understand them . Manifest . Oncreate . Onstart . Onresume

当然了相应的注销。

我想了UI更新方案是有道理的投入onresume和的onPause ...您的想法?

I think for a UI update scenario makes sense to put in onresume and onpause... your thoughts?

推荐答案

如果接收器只接收这将导致你更新GUI则有两种选择事件。注册以获得他们OnResume,如果你想让它仅仅更新时的活动是在前景中的onPause注销。或在onStart和的onStop之间,如果你想更新时,活动甚至是部分可见的(即模态的屏幕部分阻断活性)。 看到这里共有2页了。寻找有三个关键的循环,你可能是你的活动中感兴趣的监控:

If the receiver is only to receive events that would cause you to update the GUI then there are two options. Register to receive them in OnResume and unregister in OnPause if you want it to only update when the activity is in the foreground. OR between onStart and onStop if you want to update when the activity is even partially visible (i.e. a modal screen is partially blocking the activity). See here about 2 pages down. Look for "There are three key loops you may be interested in monitoring within your activity:"

这篇关于其中,注册广播接收器的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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