电池的最佳使用 [英] Optimal usage of battery

查看:111
本文介绍了电池的最佳使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个程序员有什么我可以照顾我的应用程序不养猪了大量的资源和消耗电池的措施?

As a programmer what are the measures I can take to take care that my app does not hog a lot of resources and drain the battery ?

推荐答案

根据您编写的应用程序,其中的一些可能适用于您:

Depending on the application you are writing, some of these may apply to you:


  • 请不要使用过多的网络电话。尽量保持数据的缓存,这将不经常改变,只能说他们的最后刷新10秒后运行一个完整刷新(停止滥发他们的服务器,提供了更快的响应)

  • 取消,如果他们不需要运行任何异步任务(例如,无需下载该图片/网站的其他部分,如果用户浏览了使用它的活动)

  • 请使用的onPause / OnResume的暂停/恢复游戏

  • 请使用调用OnStop /的OnStart方法来保存程序的状态,并在必要时重新加载它。请注意,在这种状态下,应用程序是不可见,如果其他应用程序所需的内存可能会被杀死,但下次运行时的意思,你要么进入onRestart()或的onCreate()

  • 避免将屏幕保持在( setKeepScreenOn(布尔)的android:keepScreenOn )。视频大概应该是唯一的实例之一,你将利用此功能

  • 避免建筑部件的更新频繁,<​​一个href=\"http://stackoverflow.com/questions/2416782/android-how-update-widget-often-but-only-when-it-is-visible\"标题=时,它的可见仅更新>只有当它是可见更新

  • Don't use excessive network calls. Try to maintain a cache of data that will change infrequently, and only run a full refresh after say 10 seconds of their last refresh (stops them spamming the server, gives a faster response)
  • Cancel any async tasks running if they are not needed (for example, no need downloading the rest of that picture/website if the user navigates out of the activity that uses it)
  • Make use of OnPause/OnResume to pause/resume games
  • Make use of the OnStop/OnStart methods to save program state and reload it when necessary. Note that in this state, an app is 'no longer visible' and may be killed if other apps require the memory, meaning the next time it is run, you'll either go into onRestart() or onCreate()
  • Avoid setting the screen to remain on (setKeepScreenOn(boolean) or android:keepScreenOn) . video should probably be one of the only instances where you would utilise this functionality
  • Avoid building widgets that update frequently and only update it when it's visible

有是显示获得呼吁暂停/恢复对Android开发者网站的不同方法一个很好的流程:

There is a nice flowchart showing the different methods that get called for pausing/resuming on the android developer site:

http://developer.android.com/reference/android/app/ Activity.html

这篇关于电池的最佳使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆