惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
K
Kaspersky official blog
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
U
Unit 42
D
Docker
I
InfoQ
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
C
Check Point Blog
The Cloudflare Blog
美团技术团队
V
Vulnerabilities – Threatpost
博客园_首页
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
A
Arctic Wolf
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Troy Hunt's Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
人人都是产品经理
人人都是产品经理
C
Cyber Attacks, Cyber Crime and Cyber Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Schneier on Security
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
The Last Watchdog
The Last Watchdog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
The Register - Security
The Register - Security
博客园 - 三生石上(FineUI控件)
Forbes - Security
Forbes - Security
NISL@THU
NISL@THU
Y
Y Combinator Blog
T
Threatpost
Microsoft Azure Blog
Microsoft Azure Blog
L
Lohrmann on Cybersecurity

博客园 - FantasySoft

PHP菜鸟手记——如何解决无法装载动态链接库的问题 穿在身上的手机——M-Dress 团购之道——双赢才是核心 Demand Media——深谙中庸之道的新媒体 云中谁寄锦书来,盛大也! 《黑客》月刊中文版第一期正式发布,很给力!推荐围观! 比尔•盖茨:未来最好的教育来自互联网 CaptureDeviceManager.getDeviceList方法返回null对象问题探究 为了生活更美好,玩游戏吧! 三言两语话委托 IronPython Tools——为IronPython度身定做的IDE 从博客园口水仗想到的 lambda与闭包 由XML Literal引发的思考 作为.NET程序员,您需要IronPython么? 大道至简——Michael看iPad 波哥大BRT带来的启示 Timberland的企业社会责任 比尔•盖茨谈教育
静态注册BroadcastReceiver的注销问题
FantasySoft · 2010-04-17 · via 博客园 - FantasySoft

2010-04-17 13:46  FantasySoft  阅读(6783)  评论()    收藏  举报

[写在前面:距离上次发布有关技术的文章已经整整一年了,人也奔三了,NBA季后赛也开打了,朋友都当爹当妈了,我也该回归了。是的,it's time! ]

     Android和OPhone是什么,我想我不需要再花什么时间去介绍了,跟着3G的潮流,这些名词已经变得炙手可热。Michael(Perhaps is my nickname. )也开始关注起Android/OPhone上的开发了。如果您也和我一样刚刚投身于这个领域,您可以参考园子里两位牛人写的系列文章,感谢他们的辛勤劳动和热心分享!

     1、Android开发之旅 by 吴秦

     2、深入Android系列 by Venus神庙 

     BroadcastReceiver是一个用于监听应用程序运行环境变化,并且对变化事件作出响应的组件。譬如说,当电池电量低、SD卡拔插或者手机启动完毕等等事件发生的时候,系统都会广播相应的事件,那么,我们在应用程序中就可以利用BroadcastReceiver对这些事件进行监听,并且执行onReceive方法作出相应的处理。

我们可以通过两种方式注册BroadcastReceiver,一是在Activity启动过程中通过代码动态注册,二是在AndroidManifest.xml文件中利用<receiver>标签进行静态注册。对于第一种方法,我们需要养成一个良好的习惯:在Activity进入停止或者销毁状态的时候使用unregisterReceiver方法将注册的BroadcastReceiver注销掉。基于此,我们很自然就会想,如果通过第二种方法注册的BroadcastReceiver,是否需要通过代码进行注销呢?基于这个问题,Michael在OPhoneSDN上提出这个疑问

     最后,Michael还是从Android的源代码中找到了这样的注释:If this BroadcastReceiver was launched through a <receiver> tag, then the object is no longer alive after returning from this function. This means you should not perform any operations that return a result to you asynchronously. 这段文字告诉我们:如果通过<receiver>标签来注册的BroadcastReceiver,那么该对象的实例在onReceive被调用之后就会在任意时间内被销毁。也就是说,我们并需要担心静态注册的BroadcastReceiver的销毁问题。

     虽然,这个过程貌似有点枉费心机,但是,Michael还找到了如何将Android源码添加到IDE中,以便在开发过程中浏览,同时还用上了很cool的版本控制软件——Git。昨晚的兜兜转转实际上收获颇丰,开心ing......