Manipulating Broadcast Receivers On Demand
来源:互联网 发布:前两年悲伤的网络歌曲 编辑:程序博客网 时间:2024/05/22 17:50
The simplest way to monitor device state changes is to create a BroadcastReceiver
for each state you're monitoring and register each of them inyour application manifest. Then within each of these receivers you simply reschedule your recurringalarms based on the current device state.
A side-effect of this approach is that your app will wake the device each time any of thesereceivers is triggered—potentially much more frequently than required.
A better approach is to disable or enable the broadcast receivers at runtime. That way you canuse the receivers you declared in the manifest as passive alarms that are triggered by system eventsonly when necessary.
Toggle and Cascade State Change Receivers to Improve Efficiency
Use can use the PackageManager
to toggle the enabled state on anycomponent defined in the manifest, including whichever broadcast receivers you wish to enable ordisable as shown in the snippet below:
ComponentName receiver = new ComponentName(context, myReceiver.class);PackageManager pm = context.getPackageManager();pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
Using this technique, if you determine that connectivity has been lost, you can disable all ofyour receivers except the connectivity-change receiver. Conversely, once you are connected you canstop listening for connectivity changes and simply check to see if you're online immediately beforeperforming an update and rescheduling a recurring update alarm.
You can use the same technique to delay a download that requires higher bandwidth to complete. Simply enable a broadcast receiver that listens for connectivity changes and initiates thedownload only after you are connected to Wi-Fi.
- Manipulating Broadcast Receivers On Demand
- Manipulating Broadcast Receivers On Demand 按需操控广播接收
- Manipulating Broadcast Receivers On DemandAndroid 电源管理专题之管理广播接收器 Broadcast Receivers
- Android broadcast receivers详细介绍
- Android 广播接收器(Broadcast Receivers)
- Android Broadcast Intents and Broadcast Receivers
- Android Broadcast Intents and Broadcast Receivers
- Windows Vista On Demand
- game on demand
- 视频点播 video on demand
- Loading Views On Demand
- On-Demand Resources Essentials
- initialization on demand holder
- On Demand Resources
- Globalize your On Demand Business
- Office Word 2007 On Demand
- Grid Computing (On Demand Series)
- Pass4Sure IBM On Demand Business
- jQuery中的.bind()、.live()和.delegate()之间区别分析
- Select语句详细剖析以及其执行顺序
- eclipse上的svn用户信息修改
- 常用的宏定义
- apk反编译步骤
- Manipulating Broadcast Receivers On Demand
- 浏览器的渲染原理简介
- 给IE浏览器工具栏添加按钮 ---此处IE9上指的是“命令栏”
- Spring IoC源码之BeanFactory
- SQLite 3 一些基本的使用
- 基于按annotation的hibernate主键生成策略
- WCS学习笔记(第四天) - 使用data bean从MyNewControllerCmd 向 MyNewView传递信息
- DDA作直线
- 110403 Bridge