i just started working on android about 4 months back.
i created a project that uses AlarmManager, the flow is like this:
AlarmManager->service->wifi not available->AlarmManager continues->service.. and so on.
this alarm may be scheduled for days, hopefully if the device is not rebooted.
I required help in the Battery drainage part of the project. How may i know the rate at which my AlarmManager Project is draining the battery. I fear that if it draining a lot of battery, my app wont be useful.
There are several things which may consume a lot of battery power, such as the display screen, access and Wifi scanning, Bluetooth, GPS, live wallpapers and so on. Roaming around on forums and stuff, I see a lot of people complaining about short battery time, and it is actually easy to understand them, but if they take a closer look at all the resources you mobile is using constantly, they wouldn't be surprised at all. Personally, I've resigned to charge my phone twice a day, when not working with it.
Nevertheless, I have a couple suggestions for you:
I am not actually that familiar with how AlarmManager works, but I suppose you could decrease the frequency of scheduled alarms to save battery time. There are a lot of applications which start automatically, not sure they use this method, though!
Use JuiceDeffender (I think) and JuicePlotter. These are apps which can monitor and plot the battery consumption in time.
Make tests: In one day schedule the alarms, in another day, don't! Then analyse the battery level.
Perhaps the folks in android.stackexchange.com have a deeper knowledge on Android power consumption. Ask them out!
Cheers!
Related
I have created an app which consuming 48 percent of battery in some device which is highest in power management task, but in some device its 5-6 %, i am running a service in background all the time which fetches the latitude and longitude and send it on server if user is logged in. but i have checked also check by logging out from app it still consumes 48 percent.
to fetch latitude and longitude o am using fused location api.
So please tell me how to resolve this issue of battery consumption in some phone and how to check which process and service is draining battery.
I agree with Lonni that the issue is the lat/long fetch. Given the scale of the power consumed, 48%, it's unlikely to be the GPS circuitry itself. I figure it's the CPU. Mobile processors are very power efficient unless they are kept active. Let me explain. An active proessor is the most power hungry device on a mobile device. So how can a processor be the biggest power hog while also being "power efficient"? By the processor being "power efficient", I mean that when the processor isn't doing anything, it goes into a very efficient lower power state where its power consumption can be over an order of magnitude less than when in the active state.
My guess is that you are keeping the processor in an active state. What you want is to keep the processor as idle as possible.
Here are my recommendations:
Use the longest interval possible between lat/long fetch. A common mistake is that more checks mean better response, but unnecessary checks generally don't improve response and just keep the processor active and consuming power for no good reason.
Never poll! Polling keeps the processor active which consumes power for no good reason. Put the processor to sleep.
Use interrupts to processes events. System libraries, such as sleep(), put the processor in an inactive state, and uses an interrupt to wake the processor back up.
Don't write your own routine if a library routine already exists. The OS/library writers are very aware of the importance of power efficiency and have written their code to be as efficient as possible.
Make your code run as fast as possible. Fast means more idle time, which drops the processor into a more efficient power state. For example, if you can get along with a lat/long check every 60 sec, and you can get your processing done in 10 sec instead of 30, you have 50 sec of idle vs 30 sec.
Use a good optimizing compiler and good optimized mobile libraries if possible. Good compilers create more efficient, faster running code. Good libraries not only run faster, they use power efficient techniques.
Use a thread pool if you are using a lot of threads. Creating and tearing down threads is costly.
Make sure you check your API specs on your devices. I can imagine that some OSs/drivers, e.g. GPS, will require the device to be explicitly turned off, while others will do so implicitly.
Here's some more information: Battery-safe coding
Aside: I already see the thought bubble: "Why are some devices using less power than others?" Some libraries are really smart, and anticipate bad programming practices and do workarounds. Others are dumb. The same with the OS, system libraries and thread scheduling.
My best guess is that the constant fetching of long and lat is draining the battery. If i remember correctly what I did a few years ago with positioning that was the case.
I would say that you should try and see the refresh-rate you want to have of your coordinates. Maybe it doesn't need to be refreshed more than 5 times per minutes. In that case you would save a lot of calls to the fetching of the coordinates and surely save your battery.
As for why it is different on some devices, I'm afraid I have no idea. Maybe the version of android used?
Edit: I don't know if Eclipse can do that and I don't think it can.
However, you may want to check this paper: http://www.usenix.org/event/usenix10/tech/full_papers/Carroll.pdf
I have an alarm manager and I check with my server every 30 minutes for new data, i want to measure battery usage of this specific task or another question how to measure battery usage of running each service and class in my application?
Whether checking every 30 minutes or every 2 hours, there shouldn't be a difference. (I'm assuming that the processing you are doing when you check is small.) Checking too often is a problem with regards to battery drain but only in situations where the interval between checks is <1 sec.
So if your question is, "What is the best interval to use?" then 30 minutes shouldn't be a problem.
If your question is, "I'm having a problem with battery drain and need to find out where it is," then this becomes a profiling question. And it gets much more complicated, especially when you are trying to view things from a class or even a light weight process (e.g. a thread) standpoint. You can do profiling at a class or thread level but it becomes very complicated unless you have hardware with special registers for recording power, current or voltage information.
If you only need to profile at a process level, there are plenty of good tools. A simple web search will suffice. Power consumption is closely tied to CPU usage. If you reduce CPU usage, say by making your program faster, you will likely also reduce energy consumption (i.e. power).
What is the best way to log GPS position (or data, to analyze) that wouldn't consume whole battery in few hours on Android? Is there some special way? Some of the tracking software available on market claim to be optimized for low battery usage.
No matter what exact approach to the code you use (e.g. service, some library, or code your self, etc, etc)... it will ALWAYS narrow down to one question:
How much resolution and how often updates are you requesting?
That's because no matter how it's coded, it will always relies on the same sensors (the GPS, wifi n tower triangulation) that is attached to the same physical hardware, and same battery.
So, general tips for better battery life is to get positions less often, to be ok with less accurate positioning, etc.
The Google Location Services (available on any device that uses Google Play) is a great time saver and it's also a very well optimized piece of code. If you want some example on how to use it feel free to check this app I did in a boring Sunday afternoon:
https://github.com/budius/photogpstag
https://play.google.com/store/apps/details?id=com.budius.photogpstag
In that I optimized for a person walking and taking photos, meaning every 3 or 5 minutes would be a good enough position and have a good lasting battery.
You can grab the source code and change the request parameters to higher accuracy/more often updates and see that the battery drain will increase.
Hey, I finished my code and everything works as it should but I'm wondering since smartphones have limited battery, CPU .. How can I check if my application will run good on older phones? and how can I check if my app consumes the phones battery?
Thanks
The only way to really know it to test the app in the phones.
That said, you can profile it and make educated guesses based on how CPU-intensive is your app, for how long is it running, if you have services using cpu continuously, etc.
There are a few things to consider:
The main battery drain is the screen. If you keep any kind of screen lock (even dim), it will destroy the battery.
Any other lock (wifi, etc.), will induce battery drain. Do you use them? Do you need them? Do you release them as soon as they're not needed?
Do you have hardware listeners (e.g., location, accelerometer), unregister them as soon as they're not needed
Take a look at this video: http://www.google.com/events/io/2009/sessions/CodingLifeBatteryLife.html
Also take a look on
http://developer.android.com/guide/developing/debugging/debugging-tracing.html
I'm currently developing with Android SDK, and because I'm building an application based on camera, I cannot use the emulator to test it.
This means that the following scenario happens quite frequently
I connect my phone to USB the battery is 50%
I disconnect it before it is fully charged, e.g. 80%
I have to leave, and I want to take my phone with me
I come back and connect again and so on...
I read that Lithium-ion batteries don't suffer the memory effect, but, on the other hand, I also read that one should wait until the battery is fully charged before disconnecting it from the USB.
So, I'm wondering if the way I'm using the phone now for debugging may damage or reduce the life of my battery
Any advice is appreciated
First of all, I'm not an expert in this subject.
Lithium-ion battery, as you say, does not suffer the charge memory effect but they have the "digital memory" (affects the accuracy % remaining battery) as reflected in this article (so you have to fully-discharge - fully-charge periodically the battery to avoid this):
Source: http://www.techrepublic.com/blog/five-tips/five-tips-for-extending-lithium-ion-battery-life/289
More info about it:
"Partial discharge on Li-ion is fine; there is no memory and the battery does not need periodic full discharge cycles other than to calibrate the fuel gauge on a smart battery"
So partial discharge is not a problem. The worst condition is keeping a fully charged battery at elevated temperatures
Source: http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries
About the need to fully-charge in Lithium-ion batteries, I did find a source about it, but in Apple support you can find this:
"You can disconnect and use your iPod before the battery is fully charged. You don't have to wait until the battery is completely empty before charging it again. This is because lithium-ion batteries, such as those used in iPod, have none of the memory effects seen in nickel-based rechargeable batteries"
Source: http://support.apple.com/kb/ht1384
Conclusion: Your partial charges/discharges won't be noticeable. If you want to extend the battery life, follow the suggestions you can find in the first two articles (avoid hot, don't let fully discharge... etc).