Android 性能优化(15)网络优化( 11)Manipulating Broadcast Receivers On Demand
Manipulating Broadcast Receivers On Demand
This lesson teaches you to
You should also read
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
You 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.
Android 性能优化(15)网络优化( 11)Manipulating Broadcast Receivers On Demand的更多相关文章
- 《Android开发艺术探索》读书笔记 (13) 第13章 综合技术、第14章 JNI和NDK编程、第15章 Android性能优化
第13章 综合技术 13.1 使用CrashHandler来获取应用的Crash信息 (1)应用发生Crash在所难免,但是如何采集crash信息以供后续开发处理这类问题呢?利用Thread类的set ...
- Google 发布的15个 Android 性能优化典范
2015年伊始,Google发布了关于Android性能优化典范的专题,一共16个短视频,每个3-5分钟,帮助开发者创建更快更优秀的Android App.课程专题不仅仅介绍了Android系统中有关 ...
- Android 性能优化(7)网络优化( 3) Optimizing User-Initiated Network Use
Optimizing User-Initiated Network Use This lesson teaches you to Pre-fetch Network Data Check for Co ...
- Android性能优化典范(二)
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...
- android app性能优化大汇总(google官方Android性能优化典范 - 第2季)
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...
- Android性能优化典范 - 第2季
Google发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的缩放,缓 ...
- Android 性能优化探究
使用ViewStub动态载入布局.避免一些不常常的视图长期握住引用: ViewStub的一些特点: 1. ViewStub仅仅能Inflate一次,之后ViewStub对象被置空:某个被ViewStu ...
- android 性能优化
本章介绍android高级开发中,对于性能方面的处理.主要包括电量,视图,内存三个性能方面的知识点. 1.视图性能 (1)Overdraw简介 Overdraw就是过度绘制,是指在一帧的时间内(16. ...
- Android性能优化典范第一季
2015年伊始,Google发布了关于Android性能优化典范的专题,一共16个短视频,每个3-5分钟,帮助开发者创建更快更优秀的Android App.课程专题不仅仅介绍了Android系统中有关 ...
随机推荐
- [bzoj2179]FFT快速傅立叶_FFT
FFT快速傅立叶 bzoj-2179 题目大意:给出两个n位10进制整数x和y,你需要计算x*y. 注释:$1\le n\le 6\times 10^4$. 想法: $FFT$入门题. $FFT$实现 ...
- operamasks—omGrid/omBorderLayout的混合使用
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs&q ...
- Spring集成Redis方案(spring-data-redis)(基于Jedis的单机模式)(待实践)
说明:请注意Spring Data Redis的版本以及Spring的版本!最新版本的Spring Data Redis已经去除Jedis的依赖包,需要自行引入,这个是个坑点.并且会与一些低版本的Sp ...
- AutoCAD如何方便截图放到Word文档,改成白底黑字
将模型视图切换到布局2即可 比如下图所示的效果 先回到模型视图把所有线条颜色都改成白色,然后添加适当的标注(比如要受力分析,则在CAD中绘制箭头也很方便的),文字说明.然后切换到布局2就OK ...
- 2015 Multi-University Training Contest 9-1007 Travelling Salesman Problem
Problem Description Teacher Mai is in a maze with n rows and m columns. There is a non-negative numb ...
- hdu 1711 KMP算法模板题
题意:给你两个串,问你第二个串是从第一个串的什么位置開始全然匹配的? kmp裸题,复杂度O(n+m). 当一个字符串以0为起始下标时.next[i]能够描写叙述为"不为自身的最大首尾反复子串 ...
- Python按行输出文件内容具体解释及延伸
下面两端測试代码分别为笔者所写,第一段为错误版本号.后者为正确版本号: #! /usr/bin/python2.7 try: filename = raw_input('please inpu ...
- fused multiply and add
1 要解决的问题 计算x*y + z?其中x.y.z都是浮点数. 2 普通的计算方式 e=3; s=4.734612 × e=5; s=5.417242 ----------------------- ...
- Spring 之AOP 面向切面编程
AOP相关术语: Joinpoint (连接点):所谓连接点是指那些被拦截到的点,在spring中,这些点指的是方法,因为spring 只支持方法类型的连接点. Pointcut(切入点):所谓切入点 ...
- HIbernate- SQLQuery 简易
package cn.demo; import java.util.Arrays; import java.util.List; import org.hibernate.SQLQuery; impo ...