开发者

Very Battery Friendly App/Widget(Android)

开发者 https://www.devze.com 2023-03-17 10:24 出处:网络
I have been looking around here and There, and I have become curious. I was wondering if there is anything staple that is usually applied to android apps to make sure they do not become battery hungr

I have been looking around here and There, and I have become curious.

I was wondering if there is anything staple that is usually applied to android apps to make sure they do not become battery hungry. Such as 开发者_运维技巧portion of code that is normally added to make sure app gets closed all the way when it is exited?

What would be the best practice(code wise) that I could do to make sure my app/widget does not drain battery life.

For example lets just say my app is an informative one with a little bit of user interaction or a simple widget(Not a game etc.)


I think the best practice is kindof a dead giveaway: "don't make silly mistakes". Ofcourse, that is harden then it seems.

  • Closing all the way is not something you need to think of. You should keep as little as possible memory occupied. NOT because that uses battery, but the less you use, the more programs can stay in memory (so the less gets closed!) and can be started without too much trouble. Reloading stuff is expensive, keeping it in memory isn't!
  • Be aware that a service (background process, alarm, etc) is costly, because it can actually DO something when it is not in view. Do make sure those are closed.
  • Background stuff that should be there (updates, loading etc) should use as little as possible resources, just as normal usage
  • normal usage: Use little resources like network, location etc etc. It kinda works like you think. Also, the less memory you use, the more other programs can stay in memory and lower battery life.


If you investigate about battery consumption you will find most of the charged is consumed by wifi,bluetooth,GPS enabled,system and display.So when developing application it should be checked by user how he is using the resource.Also calling finish() while exiting the application free some resources(memory)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号