位置: 编程技术 - 正文

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

  • 计提所得税分录计提的时候金额比实际缴纳多
  • 税务金三系统是什么?
  • 合并报表会计未分配利润怎么填写?
  • 城建税计税依据扣除增值税期末留抵
  • 无形资产多摊销了怎么办
  • 减值准备为什么影响利润总额
  • 固定资产清理净损失计入什么科目
  • 累计缴税扣除额
  • 预缴的附加税月末结转吗
  • 车间报销办公费计入什么科目
  • 特许权使用费增值税征收品目
  • 企业向个人借款的会计分录
  • 材料成本差异月初贷方余额表示什么
  • 清税证明要什么证件
  • 外出经营许可证办理流程
  • 开票金额大于收款金额如何处理
  • 委托贷款利息收入账务处理
  • 工程款为什么要扣税
  • 开增值税专用发票需要合同吗
  • 产权转移书据有哪些
  • 公司参展费取得发票怎样做账?
  • 冲红的进项税发票入账处理
  • 所得税申报季末资产总额怎么填
  • 买二手设备需要注意的事项
  • 租赁厂房水电费怎么算
  • 小规模印花税怎么报
  • 税务局增项
  • 采购开票税率
  • 客户的佣金
  • 文件校验有什么用
  • 购入办公桌椅怎样入账
  • 电脑装机光盘
  • sccenter.exe - sccenter是什么进程 有什么用
  • Pont Rouge (Red Bridge) over the Palmer River in Sainte-Agathe-de-Lotbinière, Quebec, Canada (© Jean Surprenant/Getty Images)
  • 纽约公共图书馆开放时间
  • 残保金计入税金及附加合理吗
  • video.js能播放什么格式
  • Python 计算机视觉(八)—— OpenCV 进行图像增强
  • ChatGPT是如何训练得到的?通俗讲解
  • html用语
  • 2022年微信小程序游戏
  • php代理访问
  • php 压缩文件
  • 重复上次命令
  • python数学建模资料
  • 加计抵减退税的会计分录
  • vue2跟vue3
  • 合并报表的会计主体
  • 企业筹建期间
  • oracle与mysql的优缺点对比
  • mongodb的配置文件
  • 其他应付款贷方表示什么意思
  • 工装费用制度
  • 公司把股权转让给个人员工该怎么办
  • 转让技术所有权是其他业务收入吗
  • 营改增后租金收入交什么税
  • 小规模减免税收入
  • 红字发票最多几个月
  • 销售发奖金感谢说说
  • 转账支票办理收款所要拿的单证
  • 预收账款账务处理分录
  • 个人承担的社保算公司的费用吗
  • 收到红字发票进项税怎么做账务处理
  • mysql处理
  • mysql中分组
  • 关机并重启是怎么回事
  • linux查看磁盘挂载的命令
  • win8.1怎么关机快捷键
  • windows8连wifi
  • 两种方法教你锁门
  • win10系统用正版有什么好处
  • 怎么快速更换苹果手机壁纸
  • css spirit
  • 批处理修改文件修改日期
  • 厦门翔安到同安有多远
  • jquery的show和hide
  • android 自定义dialog
  • 物业公司收取物业费要交税吗
  • 技术服务费减免企业所得税政策
  • 转卖车辆车船税多少
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设