位置: 编程技术 - 正文

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

  • 税控盘开票软件访问数据库错误
  • 房租租赁房产税由哪方缴纳
  • 固定资产清理的账务处理
  • 工会经费支付福利方案
  • 营业外收入怎么算增值税
  • 应付债券到期偿还的会计处理
  • 增值税纳税申报表附列资料(三)
  • 社保申报后不能缴费
  • 一般纳税人可以开1%的发票吗
  • 会计报废怎么处理
  • 应交税费明细表填制
  • 报销应聘人员差旅费
  • 公司买入股票要交所得税吗?
  • 补充医疗保险应享尽享方案
  • 商业汇票如何申领
  • 红字发票信息开错该怎么撤回与相关会计处理
  • 原材料呆滞物料处理方法
  • 所得税汇算清缴分录怎么做
  • 购销企业
  • 企业在筹办期间发生的开办费计入管理费用账户
  • 税收分类编码里的劳务是劳务派遣的意思吗
  • 红字发票怎么申报?
  • 记账凭证的科目不会填
  • 有限公司资本公积转增股本要交税吗
  • 商票背书需要对方开发票吗
  • 收取施工队管理费
  • 固定资产报废处理流程图
  • 资源税纳税期限按月还是按季
  • win 10 请稍后
  • 在windows7是一种
  • win11怎么调整任务栏位置
  • 收到广告费收入怎么做分录
  • php数组函数实现机选双色球
  • 诉讼费属于什么科目类别
  • 珠穆朗玛峰的壮观
  • 摇树的英文是什么
  • 魔改toolbox
  • bert数据增强
  • 采购的原材料无保质期
  • 汇算清缴有问题怎么办
  • 公司缴个人所得税吗
  • 纳税人兼营不同税率
  • 以房租入股股份怎么计算
  • webservice api接口
  • 项目支出可以列支差旅费吗
  • 实收资本核算有哪些要求
  • 缴存的提存金是什么
  • 国债利息收入的分录
  • 缴纳的工会经费现金流量表怎么记
  • 未开票的收入如何确认分录
  • 在施工期间,承包商可能遇到不能预见
  • 认证固定资产发票如何入账
  • 退货收到红字发票怎么办
  • 企业购车购置税怎么算
  • 工程总包含设备工程吗
  • 暂估出库需要确认收入吗
  • 打车费用会计分录
  • 新手公司内帐怎么做
  • 将Reporting services的RDL文件拷贝到另外一台机器时报Data at the root level is invalid的解决方法
  • ubuntu系统中如何安装WiFi驱动
  • freebsd服务器搭建
  • softmangerlite.exe是什么进程 有什么用
  • GhostXP装机版v3.0
  • win10桌面图标无法正常显示
  • Vsftpd+tcp_wrappers控制主机和用户访问
  • cocos2d::DrawPrimitives和DrawNode分别实现画板功能
  • 微信小程序商品列表代码
  • renderjs echarts
  • jquery移除
  • 使用JQuery FancyBox插件实现图片展示特效
  • perl 运算
  • unity mobile3d
  • jquery密码验证
  • 安卓手机更新时间
  • 函数 python
  • 详解Bootstrap四种图片样式
  • 如何利用python写爬虫
  • javascript精度问题的原因
  • 发票开了,税务局上查不到信息是怎么回事
  • 北京朝阳税务局办税大厅
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设