最近做了个demo,用到广播,目的是监听蓝牙连接是否断开。断开时,弹出对话框告知已断开。
开始的时候当连接断开时发出警告用的是AlertDialog,这个东西必须是由activity创建,而我有多个activity。于是就悲催的在N个Activity里注册and销毁receiver(这是有多彪啊)。。。。
而当你真正收到连接断开的时候其实早800年前就被断开了,这个时间差内,再读写之类的会有异常,这时就要有自定义广播~~于是我凌乱了。
凌乱之后,又自定义过滤器,静态注册接收器。这时AlertDialog的问题出现了。我又不淡定了,又是一阵凌乱后,发现再写个activity设置成dialog,再设置透明神马的不就OK(之前是有多蠢啊)。当收到广播的时候转到alertactivity,为了避免多次弹出对话框,在AndroidManifest.xml里设置了单例。
本以为这就完了,但是发现这个静态注册的广播在进程都kill了还在那给我提示,疯了。。。
各种去
groups.google上搜贴无果后各种看api,发现AndroidManifest中receiver里的enable属性,属性描述如下:
Whether or not the broadcast receiver can be instantiated by the system — "true" if it can be, and "false" if not. The default value is "true".The <application> element has its own enabled attribute that applies to all application components, including broadcast receivers. The <application> and <receiver> attributes must both be "true" for the broadcast receiver to be enabled. If either is "false", it is disabled; it cannot be instantiated.
水平太烂凑活瞎理解吧。。想着干脆得到PackageManager后直接把application的enable制成false,结果是收不到广播了,程序也再启动不起来了(这个应该可以解决,下面再说)。。,无奈~
继续看,看到setComponentEnabledSetting,描述如下:
Set the enabled setting for a package component (activity, receiver, service, provider). This setting will override any enabled state which may have been set by the component in its manifest.
觉得可行就,先得到receiver这个组件后把他的enable制成false,广播关闭了。but下次程序启动的时候广播木有了,真的木有了啊~~~百思不得其解
最终把AndroidManifest里receiver的enable属性显示声明成true,这次可以了。
觉得之前如果把在AndroidManifest里把application的enable属性也显示声明成true,也应该可以,不过没有试。
分享到:
相关推荐
EventReceiver注册工具,Dll文件需要手动加入assembly文件里,然后重启IIS
本篇文章主要介绍了Android的广播Receiver动态注册和静态注册示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
您可以使用 Windows 的“程序和功能”实用工具(添加/删除程序)卸载 Receiver。 注意:如果曾使用 Citrix Receiver Updater 安装 Receiver,请勿使用此方法。 在某些情况下,卸载 Receiver for Windows 不会删除...
citrix receiver for mac
CitrixReceiver.dmg
GNSS receiver and the receiver clock offset from measurements of at least four pseudoranges.
simple FM receiver in Matlab
CitrixReceiver.exe
最新版 Citrix Receiver,最新版 Citrix Receiver ,方便安装后完可以连接服务器。
Fast Shadow Receiver V1.45 Fast Shadow Receiver 通过CPU的实时计算来换取GPU的渲染性能的方案 场景静态合批被动态阴影打断的问题
Android关于广播的静态注册和动态注册及广播数据写入界面...静态注册是直接在AndroidManifest里面先进行注册,添加receiter,其中需要写入你的Broadcast Receiver的名字,我这里是MyReceiver,也可以写其他的名字,ena
MirrorOp Win Receiver V 0.2.17.8
主要介绍了深入Android中BroadcastReceiver的两种注册方式(静态和动态)详解,具有一定的参考价值,有需要的可以了解一下。
CitrixReceiver
syslog receiver syslog接收测试工具 MegaLogSyslogTestReceiverV2.zip
Sender-receiver 消息 ,还是老话,学习JMS和activemq必看资料一直
GSM Receiver Simulation
CitrixReceiver老版本安装