位置: 编程技术 - 正文

Developing for Android, IV: The Rules: Networking

编辑:rootadmin

推荐整理分享Developing for Android, IV: The Rules: Networking,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

This section covers practices around network behavior of applications.

Don’t Over-Sync

Sending data to and from the cloud is one of the largest consumers of battery. The problem is not that any particular network transaction kills the device, but rather the sheer number of background applications and services making these requests and the side effect on the inability of the device to sleep (or for the radio to enter low power mode) for any reasonable length of time causes a significant drain on the battery in general. If you don’t need the data immediately, don’t get it. If you need the data sometime in the future, batch it up with other system requests with JobScheduler or GCM Network Manager.

Here are some general tips for avoiding over-syncing:

Use Google Cloud Messaging (GCM). Do not establish new persistent connections to the device.Use JobScheduler (on API and later) or GCM Network Manager(which works across many releases, using JobScheduler internally on API and later) to benefit from batching and coalescing from other sync requests on the device. These APIs can also be used to ensure that some operations only happen when the device is in an appropriate idle state.Do not poll. Ever.Only sync what you need to. Data syncing has been found to be one of the biggest culprits of battery usage and overall system health, so app developers need to think carefully about the type of data that really needs to be synced, as well as how often it should be synced for a good user experience.See these reference articles for more information and strategies:Minimizing the Effect of Regular Updates, Transferring Data Using Sync Adapters, and Optimizing Downloads for Efficient Network Access.Avoid Overloading the Server

When a server request fails, use exponential back-off techniques to avoid hammering the server with constant, repeated requests. Also, never synchronize against wall-clock time to avoid problems with the server being hit by large loads at these absolute times.

Don’t Make Assumptions about the Network

When making network calls, be sure to call NetworkInfo.isConnected() to ensure connectivity.

Developing for Android, IV: The Rules: Networking

Also, it is not possible to know when or if a network request will actually succeed, which is yet another good reason to not make network requests on the UI thread or in other places requiring fast or synchronous behavior.

Develop for Low End Networks

The Develop for the Low End rule in the Performance chapter is as true for network performance as it is for raw device hardware performance. If your application is dependent upon network performance for content (such as a video or music application), then you should develop on a device that has a slower network connection, just to understand the implications in markets that do not have easy access to fast network speeds. If your application can get much of the content across with text (such as messaging or social apps), it is important to be able to make that work without being dependent on slower network times for associated media components. 2G networks, in particular, are important to test against since this is a slow network speed that is very prevalent in some markets.

Design Back-End APIs to Suit Client Usage Patterns

There is a tendency in back-end applications to provide a general purpose API for all of their clients. Although this is a reasonable strategy for back-end systems, it is not good for the client because the application ends up transferring and processing a lot of data on a small device while some calculations could be made on the server.

For example, if your application displays a feed of mixed content, make sure the client can fetch that information in a single request and that the returned data is suitable for caching in pieces. You generally want your client to be able to identify entities so that it can persist them and also avoid duplicates of the same objects in memory.

While doing this, many APIs return hierarchical data where all relations are denormalized. Although this approach is preferred for most web clients, it is not good for mobile clients where persisting data and serving it from disk is important.

The more information the client has about the data it is displaying, the more efficient it can be. The application can make a careful selection of what to cache, what to prune, and how to invalidate layout when new data arrives. Treating the client application like a simple HTML renderer will miss out on all of these advantages.

Developing for Android, III: The Rules: Performance OnAndroid,performanceandmemoryarecloselyintertwined,sincethememoryfootprintoftheoverallsystemcanaffecttheperformanceofalloftheprocesses,andsincethegarbagecollectorcanhaveasignificantimpactonruntimeper

AsyncTask 转载自

android中解析doc、docx、xls、xlsx格式文件 解析doc,要tm-extractors-0.4.jar这个包解析xls,要jxl.jar这个包下载jxl.jarpublicstaticStringreadDOC(Stringpath){//创建输入流读取doc文件FileInputStreamin;Stringtext=null;//Envir

标签: Developing for Android, IV: The Rules: Networking

本文链接地址:https://www.jiuchutong.com/biancheng/384185.html 转载请保留说明!

上一篇:Android入门——电话拨号器和四种点击事件(android零基础入门教程)

下一篇:Developing for Android, III: The Rules: Performance

  • 企业所得税年报申报时间
  • 购买的携税宝费用怎么做账?
  • 预收账款借方余额可以计入应收账款的哪方
  • 企业所得税可以不交吗
  • 社会组织属于非法人组织吗为什么
  • 职工薪酬会计准则
  • 物业公司可以开什么项目的发票
  • 非税收入包括哪些
  • 盈利能力分析对企业发展的意义
  • 其他扣款税后应该怎么做账?
  • 短期借款的会计科目
  • 生育津贴个税汇算清缴可以扣除吗
  • 企业发工资哪些需要缴个人所得税?
  • 管理费用的纳税调整
  • 小微企业工会经费的减免政策2023
  • 发生广告费用会计分录
  • 本期认证本期不抵扣下月再抵扣
  • 小规模纳税申报表下载
  • 如果没有预缴就开票会怎样?
  • 分期收款销售的核算中发出商品时借什么账户
  • 汇算清缴做完还能改账么
  • 哪些工资薪酬可以进行税前扣除?
  • 少数股东损益为正,归属毌公司为负
  • 付款网站制作
  • 电梯维修公司发展前景
  • word文档打印时不打印批注
  • 增值税税率调整差额怎么计算
  • svchost程序错误怎么修复
  • 税控盘抵减
  • 深度deepin系统安装教程
  • win10记事本在哪找
  • 微软手机
  • 一般纳税人购进农产品如何抵扣进项税额
  • php require include
  • 绣球花的叶子出现了斑点,这是怎么了?
  • 短期投资需要结转吗
  • 会计费用科目分类表
  • php的难点
  • java项目报错
  • 位于阿曼和迪拜的大学
  • apache无法访问自己的页面
  • 蓝牙11
  • Js中操作数组的方法
  • php socket编程
  • 金蝶k3现金流量表编制如何生成数据
  • 小规模纳税人附加税会计分录
  • vj刷题
  • 标准工资表怎么填
  • 计提加计抵减
  • 固定资产盘点盘什么
  • 代开增值税额与实际缴款额差一分钱如何入账?
  • 长期应付款的会计编号
  • 建筑企业的安全技术措施
  • 分包管理费取费标准
  • 长期股权投资如何入账
  • 开红字发票如何做分录?
  • 预收款退还如何处理
  • 汇算清缴后多交的企业所得税能退吗
  • 小微企业即征即退
  • mysql5.7.19 zip 详细安装过程和配置
  • xp文件夹选项在哪里打开
  • mac怎么共享wifi密码给iphone
  • dos命令 新建文件
  • ubuntu系统怎么进入命令行
  • w7打穿越火线
  • 将windows的文件上传到ubuntu
  • win7重新安装windows
  • win10系统无线网络连接在哪
  • win8系统启动不了如何修复
  • unity3d读取gis数据
  • Linux中获取某个进程的系统调用以及参数(故障排查案例)
  • n归档是什么软件
  • python生成docx
  • js打开浏览器新的tab页
  • u3d官方
  • android 自定义linearlayout 宽度计算不对
  • python基于django的项目
  • jquery的实现原理
  • 电子税务局开的发票怎么作废
  • 福州市税务局领导班子成员名单
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设