位置: 编程技术 - 正文

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

  • 增值税发票选择确认平台打不开怎么办?
  • 印花税购买使用要求及印花税会计分录?
  • 住宿费可以抵扣进项吗
  • 销项税能抵扣么
  • 职工的困难补助计入什么科目
  • 借款给别的公司收到的利息会计分录怎么写
  • 已认证未抵扣的进项怎么填写
  • 仓库打包用的物品计什么科目
  • 增值税为什么不用计提
  • 甲方也要跟项目走的吧
  • 政府扶持资金要还吗如村委借给企业对吗
  • 个体户认定一般纳税人
  • 发票到了款未付账务处理
  • 跨年的发票作废账务如何处理
  • 房地产企业老项目增值税
  • 帮别的公司做账的叫什么公司
  • 营改增之后税务是否可以征收入库?
  • 软件企业证书应该考什么
  • 坏账损失如何连续计提
  • 消耗性生物资产的账务处理
  • 补发工资如何缴纳工人所得税的法条
  • 行政单位代管资金怎么做账
  • 资产减值损失月末需要结转吗
  • 贴现利息计算器
  • 投资性房地产企业有哪些
  • 汇算清缴的租赁费怎么算
  • 东芝t351笔记本
  • 季节性停工是什么
  • 超市打折优惠
  • vue打开窗口
  • 操作系统的安全目标主要包括哪些?
  • 程序员编程代码大全
  • 如何把文档转换成二维码
  • 无线路由器如何桥接wifi信号
  • 金融商品转让的增值税怎么计算
  • 房地产企业预售房产怎么缴税
  • PHP:curl_copy_handle()的用法_cURL函数
  • win10磁盘碎片整理打不开
  • php linq
  • 华沙的教堂
  • crontab不执行的原因和解决方案
  • vue3 ts知乎专栏
  • php foreach as
  • 一年的云信承兑汇票如何提现
  • Diffusion-GAN: Training GANs with Diffusion 解读
  • 对公账户的银行卡号是几位数
  • 44岁就没有月经了正常吗
  • ubuntu20.04.1安装
  • ai 绘画原理
  • spring的文章
  • 预付劳务款项会计分录
  • 预收款怎么做表格
  • 工资直接计入管理费用了怎么办
  • 结转个人承担的社保费分录
  • 企业投资收益要交增值税吗
  • 个人所得税数据怎么导入新电脑
  • 以权益结算的股份
  • 住房公积金中的钱可以当首付吗?
  • 餐饮行业分录大全
  • 工地扬尘检测仪图片
  • 净资产增加数怎么计算
  • 企业购买理财产品收益要交税吗
  • 生产过程中产品质量问题
  • 股票股利应该何时分摊
  • 主营业务成本工资计提吗
  • 开出商业承兑汇票怎么做分录
  • 冲销预付账款后怎么做账
  • 法人借给公司钱怎么写情况说明
  • 无法在你的位置安装windows
  • mysql查询语句大全讲解
  • 全面解析皮炎
  • win8.1打开软件显示Error远程配置获取失败请重新启动
  • win10怎么用xp经典主题
  • 在ubuntu上安装gcc
  • win7系统出现蓝屏
  • 使用灭火器人要站在上风口还是下风口
  • node.js中fs模块
  • unity 角色控制器设置isTrigger问题
  • 国家税务总局39号文
  • 国家税务局关于印发的通知
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设