Manipulating Broadcast Receivers On Demand 按需操控广播接收
来源:互联网 发布:hdp直播软件下载 编辑:程序博客网 时间:2024/06/16 06:21
The simplest way to monitor device state changes is to create a BroadcastReceiver
for each state you're monitoring and register each of them in your application manifest. Then within each of these receivers you simply reschedule your recurring alarms based on the current device state.
A side-effect of this approach is that your app will wake the device each time any of these receivers is triggered—potentially much more frequently than required.
A better approach is to disable or enable the broadcast receivers at runtime. That way you can use the receivers you declared in the manifest as passive alarms that are triggered by system events only when necessary.
Toggle and Cascade State Change Receivers to Improve Efficiency
Use can use the PackageManager
to toggle the enabled state on any component defined in the manifest, including whichever broadcast receivers you wish to enable or disable 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 of your receivers except the connectivity-change receiver. Conversely, once you are connected you can stop listening for connectivity changes and simply check to see if you're online immediately before performing 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 the download 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 Training - Performance】优化电池续航能力[Lesson 4 - 按需操控Broadcast Receivers是否开启]
- Android 广播接收器(Broadcast Receivers)
- Broadcast 广播发送及接收
- Broadcast 广播发送及接收
- 【Android】利用广播Broadcast接收SMS短信
- 使用 Broadcast Receiver 接收广播消息
- Silverlight 性能优化 - 按需加载 (on demand loanding)
- Loading Views On Demand[按需加载View]
- Utility Capacity on Demand(服务器按需扩容技术)
- Android broadcast receivers详细介绍
- Android Broadcast Intents and Broadcast Receivers
- Android Broadcast Intents and Broadcast Receivers
- 游走Android系列之广播接收(Broadcast Receiver)
- Broadcast Receiver接收并处理自定义Action广播通知
- Broadcast receiver 动态注册 & 作为内部类接收广播 详解
- 崩溃分析
- 关于Android线程的几点说明
- Determining and Monitoring the Connectivity Status 根据网络连接状况去省电
- 一些注意事项
- H.264中的基本概念与基本知识
- Manipulating Broadcast Receivers On Demand 按需操控广播接收
- 为什么是“51
- 第八周项目一之类成员函数实现功能
- Creating a View Class 创建一个视图类
- Custom Drawing 自定义绘制
- Android学习笔记
- 项目一之友元函数实现功能
- php curl研究笔记
- DataTable 数据分页