Android 性能优化(7)网络优化( 3) Optimizing User-Initiated Network Use
Optimizing User-Initiated Network Use
This lesson teaches you to
- Pre-fetch Network Data
- Check for Connectivity or Listen for Changes
- Reduce the Number of Connections
Quick handling of user requests helps ensure a good user experience, especially when it comes to user actions that require network access. You should prioritize low latency over power conservation to provide the fastest response when optimizing network use that is a direct result of user actions. Attaining an optimal network traffic profile for your app, while making sure that your users get fast responses, can be a bit challenging.
This lesson teaches you how to optimize network use for user-initiated actions and reduce battery consumption.
Pre-fetch Network Data
Pre-fetching data is an effective way to reduce the number of independent data transfer sessions that your app runs. With pre-fetching, when the user performs an action in your app, the app anticipates which data will most likely be needed for the next series of user actions and fetches that data in bulk. Battery power consumption is reduced for two reasons:
- Because your app pre-fetches data only when the the mobile radio is already awake from the user's action, and so does not incur the overhead of waking up the mobile radio.
- The app pre-fetches data for anticipated user actions, each of which might otherwise require separate requests that each incur waking up the mobile radio.
Tip: To explore whether your app might benefit from pre-fetching, review your app's network traffic and look for situations where a specific series of user actions almost always results in multiple network requests over the course of the task. For instance, an app that incrementally downloads article content as a user views it might be able to pre-fetch one or more articles in categories the user is known to view.
Watch the video on effective pre-fetching which describes what pre-fetching is, where to use it, and how much data to pre-fetch. For more details, see Optimizing Downloads for Efficient Network Access.
Check for Connectivity or Listen for Changes
Searching for a cell signal is one of the most power-draining operations on a mobile device. Your app should always check for connectivity before sending a user-initiated network request. If you use a scheduling service,Schedulers do this automatically for you.
- If only certain buttons in your activity depend on a network connection, use Connectivity Manager to check for a network connection before sending the network request, as instructed in Monitor for Changes in Connectivity. If there's no network, the app can save battery by not forcing the mobile radio to search.
- If your entire activity's user interface is non-functional without network access, then use Manipulate Broadcast Receivers on Demand. This technique listens for connectivity changes when your activity is in the foreground, and prevents network requests from proceeding when no connectivity exists. That is, if your app detects that connectivity has been lost, it disables all of its receivers, except for the connectivity-change receiver. An example would be a news app that presents an activity with a full-screen view of news snippets and does no pre-fetching. Any snippet a user taps would require a network connection.
A best practice for user-initiated traffic is to first check for a connection using Connectivity Manager, and if there is no connection, schedule the network request for when the connection is made. Schedulers will use techniques such as exponential backoff to save battery, where each time the attempt to connect fails, the scheduler doubles the delay before the next retry.
Note: To check for connectivity for app-initiated traffic, see Optimizing App-Initiated Network Use.
Reduce the Number of Connections
In general, it's more efficient to reuse existing network connections than to initiate new ones. Reusing connections also allows the network to more intelligently react to congestion and related network data issues. For more information on reducing the number of connections used by your app, see Optimizing Downloads for Efficient Network Access.
Android 性能优化(7)网络优化( 3) Optimizing User-Initiated Network Use的更多相关文章
- Android 性能优化(4)Optimizing Layout Hierarchies:用Hierarchy Viewer和Layoutopt优化布局
Optimizing Layout Hierarchies This lesson teaches you to Inspect Your Layout Revise Your Layout Use ...
- Android性能优化典范第二季
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitma ...
- 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性能优化问题总结
性能优化这块,分为UI性能优化.内存优化.数据库优化.网络优化.耗电优化等等.可以从1.如何发现问题,2.怎么解决问题,3.解决效果对比,这几个方面去描述.举个简单例子——UI优化,可以从 UI出现什 ...
- Android性能优化之渲染
Google近期在Udacity上发布了Android性能优化的在线课程,目前有三个篇章,分别从渲染,运算与内存,电量三个方面介绍了如何去优化性能,这些课程是Google之前在Youtube上发布的A ...
- Android 性能优化探究
使用ViewStub动态载入布局.避免一些不常常的视图长期握住引用: ViewStub的一些特点: 1. ViewStub仅仅能Inflate一次,之后ViewStub对象被置空:某个被ViewStu ...
- 我把阿里、腾讯、字节跳动、美团等Android性能优化实战整合成了一个PDF文档
安卓开发大军浩浩荡荡,经过近十年的发展,Android技术优化日异月新,如今Android 11.0 已经发布,Android系统性能也已经非常流畅,可以在体验上完全媲美iOS. 但是,到了各大厂商手 ...
- 【腾讯Bugly干货分享】Android性能优化典范——第6季
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/580d91208d80e49771f0a07c 导语 这里是Android性能优 ...
随机推荐
- 如何将一个本来需要发几十条sql语句的需求优化成两条(非sql语句优化,而是解决方法)
首先声明,本人所有博客均为原创,谢绝转载! 今天接到一个需求,如下 这里解释一下,为什么是几十条,因为这里面每个公式的每个条件都是一个单独的数据如净利润就是一条sql语句,而且分散在不同的表,如果此方 ...
- msp430入门编程07
msp430中C语言的函数及实现07 msp430中C语言操作端口I/O10 msp430中C语言的模块化头文件及实现11 msp430中C语言的模块化头文件及库文件12 msp430入门学习 msp ...
- HTML5学习之语义化标签
一.为什么HTML5要引入新语义标签 在HTML5出现之前,我们一般采用DIV+CSS布局我们的页面.但是这样的布局方式不仅使我们的文档结构不够清晰,而且不利于搜索引擎爬虫对我们页面的爬取.为了解决上 ...
- World is Exploding 树状数组+离散化
Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a<b≤n,1≤ ...
- AndroidStudio NDK开发、调试测试工程
## 验证内容:1.支持NDK调试 2.支持native方法快速创建jni封装(但是没有加入extern "C"声明,会导致native方法找不到jni,进而报错) 3.支持通过修 ...
- Xcode iOS9.3 配置包 iOS10.0 配置包 iOS10.2 配置包 could not find developer disk image
在Finder状态下前往目录.快捷键:shift+command+G,填写路径/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS ...
- 手游产品经理初探(二)从营销角度看loading界面
近期開始写产品相关的专题,准备从细节入手去思考.总结一些不为人注意的细节地方. 今天给大家分享的是游戏里面都有的loading界面. 还是从几个在Facebook上排名靠前的Casino游戏的load ...
- 字节序:Big Endian 和 Little Endian
一.字节序 字节序,也就是字节的顺序,指的是多字节的数据在内存中的存放顺序. 在几乎所有的机器上,多字节对象都被存储为连续的字节序列.例如:如果C/C++中的一个int型变量 a 的起始地址是& ...
- mybatis中批量插入数据
<insert id="insertIntoDevAct" parameterType="java.util.List"><foreach c ...
- JAVA进阶-网络编程
>通过套接字连接server Socket指代套接字 >读取随意站点的首页 --------- /** * @author Lean @date:2014-10-9 */ public c ...