ConnectivityManager.CONNECTIVITY_ACTION,注册一个接收器时,始终广播? [英] ConnectivityManager.CONNECTIVITY_ACTION, always broadcast when registering a receiver?

查看:658
本文介绍了ConnectivityManager.CONNECTIVITY_ACTION,注册一个接收器时,始终广播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册一个接收器捕捉到Co​​nnectivityManager.CONNECTIVITY_ACTION的在code 的,即我不注册它在应用程序清单。所有工作正常,但我注意到,我自动只要注册我的接收器,尽管网络是已在接收广播。

I'm registering a receiver to capture the ConnectivityManager.CONNECTIVITY_ACTION in code i.e. I am not registering it in the application manifest. All is working fine but I notice that I automatically receive a broadcast as soon as I register my receiver and despite the network being already on.

我的问题是,我可以靠这个自动播放检查网络是否可用与否,即没有明确调用方法检查网络?

My question is can I rely on this automatic broadcast to check whether the network is available or not i.e. not explicitly call methods to check the network?

我只是期待一个广播当网络改变了,而不是在注册我的接收器,但事实上,我确实收到广播是非常有用的,但我可以依靠它。这是一个记录行动?

I was only expecting a broadcast when a network changed and not upon registering my receiver, however the fact that I do receive a broadcast is very useful but can I rely on it. Is this a documented action?

推荐答案

是的,这就是所谓的<一个href="http://developer.android.com/reference/android/content/Context.html#sendStickyBroadcast%28android.content.Intent%29"相对=nofollow>持久广播。持久广播发送尽快 registerBroadcast 被称为接收器。

Yes, that's called sticky broadcasts. Sticky broadcasts are sent to receiver as soon as registerBroadcast is called.

这篇关于ConnectivityManager.CONNECTIVITY_ACTION,注册一个接收器时,始终广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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