位置: 编程技术 - 正文

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

  • 带薪休假会计
  • 个人所得税征收标准表
  • 个人取得上市公司股票期权个人所得税
  • 个税返还手续费奖励员工账务处理
  • 电子发票字迹不清怎么办
  • 财务报表中负债率怎么算
  • 员工超过万人公司
  • 运输企业印花税按什么缴纳
  • 税务局代开的进项票需要认证吗
  • 一般纳税人需要申报什么税
  • 向境外分派红利怎么计算缴纳企业所得税
  • 机动船舶缴纳车船税吗
  • 固定资产计提折旧的原则
  • 金税三期社保费管理客户端v1.0.088(生产环境)
  • 退休人员返聘工资按工资薪金还是劳务报酬
  • 出口抵内销产品应纳税额分录
  • 字节跳动属于什么类型的企业
  • 资产负债表期末余额怎么算
  • 企业所得税税负怎么算
  • 小规模纳税人是小微企业吗
  • 中方人员取得的工资、薪金所得,征收个人所得税有特别规定吗?
  • 我们4月10日
  • 视同销售收入是否缴纳企业所得税?
  • 合伙企业收到对公转账
  • 海运费怎么做会计分录
  • 接受应税劳务的会计分录
  • 事业单位坏账怎么处理
  • 任务栏图标重叠一起
  • 工会经费怎么使用
  • 产品入库的业务流程
  • 小型微利企业所得税率
  • windows搜索为什么那么慢
  • windows7部分的更新安装失败怎么办?
  • php curl模块
  • echarts纵坐标加单位
  • 业务招待费会计分录
  • 法恩达尔的信
  • 基金公司做销售有前途吗
  • html入门基础
  • js获取本机ip地址
  • laravel分页
  • wordpress整站备份
  • 帐没做完怎么报增值税
  • 社会保险基数怎么办
  • 公司的基本户怎么换
  • 多缴纳的社保怎么查询
  • python3矩阵求逆
  • 资产负债表固定资产清理
  • 个税跨月更正申报怎么做
  • 房屋租赁物业费谁承担
  • 领款单有法律效力吗
  • 增值税进项税额抵扣期限最新
  • 在建工程领用原材料税费怎么处理
  • 长期股权投资会计实训心得
  • 固定资产入账要发票吗
  • 存货入库无法查明原因的短缺
  • 固定资产折旧方法的选择
  • 财务费用的科目编码是多少
  • 股东投资设备入帐与购买设备入帐的区别
  • 租房买的中央空调怎么用
  • sql中索引怎么使用
  • 证书登录什么意思
  • win8.1使用
  • win10怎么禁止用户安装程序
  • xp系统如何禁止各种窗口弹出
  • win7旗舰版显示器亮度调节
  • mac使用磁盘工具的快捷键
  • 如何检测电脑能否上网
  • 淘宝win10和正版的有什么区别
  • android界面切换与数据传递
  • js实现分页数据库数据
  • node.js redis
  • 利用js脚本模拟鼠标点击事件
  • node.js express koa
  • Android使用opencv处理图片灰度
  • 广东省电子居住证怎么查看
  • 纽约消费税多少
  • 重庆个人税务查询
  • 手表关税税率一般是多少
  • 辽宁朝阳丧葬费标准2022
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设