SlideShare a Scribd company logo
1 of 27
Battery Optimization for 
Android Apps 
Murat AYDIN 
STM 
#DV14 #BatteryOptimization @maydintr
About Me 
• Android Developer and blogger in his free time 
• Senior Software Developer at work 
• GDG Ankara member 
www.androiddeveloperdays.com 
• Author 
#DV14 #BatteryOptimization @maydintr
Why Battery is Important? 
• Limited and main resource for device to function 
• Device may be needed for an important task when the 
battery is running out of power 
#DV14 #BatteryOptimization @maydintr
Why Battery is Important? 
• Part of user experience 
• Bad user reviews and ratings 
#DV14 #BatteryOptimization @maydintr
What to do? 
• Buy extended batteries 
• Buy case batteries 
• Carry external batteries 
Trontium-reactor can charge phones 50 times-299$ 
• Carry solar charges 
#DV14 #BatteryOptimization @maydintr
What consumes the most? 
Derived from Jeff Sharkey’s presentation 
#DV14 #BatteryOptimization @maydintr
Usage Measurements 
For a 1150mAh battery: 
• Watching YouTube videos: 340mA 1150/340=3.4 hours 
• Browsing 3G web: 225mA 1150/225=5 hours 
• Typical usage,10 minute for every hour:42mA=32 hours 
• EDGE completely idle: 5mA=9.5 days 
• Airplane mode idle:2mA=24 days 
#DV14 #BatteryOptimization @maydintr
Bulk Data Transfer 
Bulk data transfer for a 6MB song: 
• EDGE (90kbps):300mA*9.1 min = 45 mAh 
• 3G (300kbps):210mA*2.7 min = 9.5 mAh 
• WiFi (1Mbps):330mA*48 sec = 4.4 mAh 
#DV14 #BatteryOptimization @maydintr
• Research by Purdue University into energy consumption 
by apps (March 2012) 
“Free apps like Free Chess and Angry Birds spend under 
25-35 percent of their energy on game play, but over 65-75 
percent on user tracking, uploading user information and 
downloading ads.” 
#DV14 #BatteryOptimization @maydintr
Radio State Machine 
#DV14 #BatteryOptimization @maydintr
Bundled vs Unbundled Transfers 
• Suppose 3 data transfer 
each 3s in every 20s 
• Unbundled 1 data 
transfer = 
3s+5s+12s=20s 
• 20s x 3 totally 60s 
• Bundled 9s+5s+12s = 
totally 26s 
#DV14 #BatteryOptimization @maydintr
Prefetch Data 
• Reduce download times 
• Minimize in-app latency 
• Dont use it aggressively 
• Prefetch data such that you will only need to initiate 
another download every 2 to 5 minutes, and in the order 
of 1 to 5 megabytes 
#DV14 #BatteryOptimization @maydintr
Batch Data 
• Create a pending transfer queue 
• Transfer from the queue when there is scheduled 
updates 
#DV14 #BatteryOptimization @maydintr
Use Traffic Stats API 
TrafficStats.setThreadStatsTag(0xF00D); 
try { 
// Make network request using HttpClient.execute() 
} finally { 
TrafficStats.clearThreadStatsTag(); 
} 
#DV14 #BatteryOptimization @maydintr
Polling? 
• Use GCM instead of polling 
• Use Inexact Repeating Alarms for pollings 
• Dont use _WAKEUP versions of alarm types 
• Implement exponential back-off pattern for pollings 
#DV14 #BatteryOptimization @maydintr
Cache Data 
• Cache as much as possible 
• Be careful about displaying stale data 
Monitor Connectivity 
• Avoid connection attempts if there is no network 
• Modify download pattern based on the connectivity type 
#DV14 #BatteryOptimization @maydintr
Compress Data 
• Compress data before transferring 
• Especially textual data 
import java.util.zip.GZIPInputStream; 
HttpGet request = new HttpGet(“http://url”); 
HttpResponse resp = new DefaultHttpClient().execute(request); 
HttpEntity entity = response.getEntity(); 
InputStream compressed = entity.getContent(); 
InputStream rawData = new GZIPInputStream(compressed); 
#DV14 #BatteryOptimization @maydintr
Compress Data 
Derived from Jeff Sharkey’s presentation 
#DV14 #BatteryOptimization @maydintr
Battery Monitoring 
• Monitor changes in charging state 
• Monitor Significant Changes in Battery Level 
• Maximize update rate when device is charging, minimize 
when discharging 
• Decrease update frequency when the battery is low 
#DV14 #BatteryOptimization @maydintr
Wakelock 
• Q: What is wakelock? 
• A: A wake lock is a mechanism to indicate that your 
application needs to have the device stay on 
• Device battery life will be significantly affected by the 
use of this API. Do not 
acquire PowerManager.WakeLocks unless you really 
need them, use the minimum levels possible, and be 
sure to release them as soon as possible. 
#DV14 #BatteryOptimization @maydintr
Wakelock 
• Use keepScreenOn instead of wakelock 
#DV14 #BatteryOptimization @maydintr
Derived from Jeff Sharkey’s presentation 
#DV14 #BatteryOptimization @maydintr
GPS 
• Use coarse network location if possible 
#DV14 #BatteryOptimization @maydintr
Trepn Profiler 
• Real-time overlay-mode allows developers to see the 
impact of their actions on performance 
• Helps developers optimize code for CPU, power usage 
and network usage 
• Profiles the entire system or a single app 
• Displays accurate battery power readings with charts 
• Supports offline analysis of data 
• Can be started or stopped from a script for Automated 
tests 
• Eclipse plug-in 
#DV14 #BatteryOptimization @maydintr
Demo 
#DV14 #BatteryOptimization @maydintr
As a Result 
#DV14 #BatteryOptimization @maydintr
Questions? 
• Twitter: @maydintr 
• Email: maydin@gmail.com 
• Web: www.ottodroid.net 
#DV14 #BatteryOptimization @maydintr

More Related Content

Similar to Battery Optimization for Android Apps - Devoxx14

Daily monitoring cbm of switchyard equipments through android app
Daily monitoring cbm of switchyard equipments through android appDaily monitoring cbm of switchyard equipments through android app
Daily monitoring cbm of switchyard equipments through android appNiraj Agrawal
 
That's Web? Extreme Optimization for the Mobile Web (Oct 2012)
That's Web? Extreme Optimization for the Mobile Web (Oct 2012)That's Web? Extreme Optimization for the Mobile Web (Oct 2012)
That's Web? Extreme Optimization for the Mobile Web (Oct 2012)Glan Thomas
 
Android Application Optimization: Overview and Tools - Oref Barad, AVG
Android Application Optimization: Overview and Tools - Oref Barad, AVGAndroid Application Optimization: Overview and Tools - Oref Barad, AVG
Android Application Optimization: Overview and Tools - Oref Barad, AVGDroidConTLV
 
Session 4708 - Omegamon for CICS customer experience at Garanti Technology
Session 4708 - Omegamon for CICS customer experience at Garanti TechnologySession 4708 - Omegamon for CICS customer experience at Garanti Technology
Session 4708 - Omegamon for CICS customer experience at Garanti Technologynick_garrod
 
Samsung Developer's Conference - Maximize App Performance while Minimizing Ba...
Samsung Developer's Conference - Maximize App Performance while Minimizing Ba...Samsung Developer's Conference - Maximize App Performance while Minimizing Ba...
Samsung Developer's Conference - Maximize App Performance while Minimizing Ba...rickschwar
 
Testing Mobile App Performance
Testing Mobile App PerformanceTesting Mobile App Performance
Testing Mobile App PerformanceTechWell
 
DevOps for Developers
DevOps for DevelopersDevOps for Developers
DevOps for DevelopersWill Button
 
Automated Irrigation
Automated IrrigationAutomated Irrigation
Automated IrrigationJoe Abhishek
 
Virtualization & Network Connectivity
Virtualization & Network Connectivity Virtualization & Network Connectivity
Virtualization & Network Connectivity itplant
 
Acting on Real-time Behavior: How Peak Games Won Transactions
Acting on Real-time Behavior: How Peak Games Won TransactionsActing on Real-time Behavior: How Peak Games Won Transactions
Acting on Real-time Behavior: How Peak Games Won TransactionsVoltDB
 
Developing Mobile Apps for Performance - Swapnil Patel, Verizon Media
Developing Mobile Apps for Performance - Swapnil Patel, Verizon MediaDeveloping Mobile Apps for Performance - Swapnil Patel, Verizon Media
Developing Mobile Apps for Performance - Swapnil Patel, Verizon MediaYahoo Developer Network
 
IOT BASED CASHLESS PETROL PUMP
IOT BASED CASHLESS PETROL PUMPIOT BASED CASHLESS PETROL PUMP
IOT BASED CASHLESS PETROL PUMPIRJET Journal
 
Syllabus tablet repair
Syllabus tablet repairSyllabus tablet repair
Syllabus tablet repairchiptroniks
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentReto Meier
 
Five Meteor Dev Power Tools - 2015-04-06
Five Meteor Dev Power Tools - 2015-04-06Five Meteor Dev Power Tools - 2015-04-06
Five Meteor Dev Power Tools - 2015-04-06Mike Seidle
 
Azure Site Recovery Loves Business Continuity
Azure Site Recovery Loves Business ContinuityAzure Site Recovery Loves Business Continuity
Azure Site Recovery Loves Business ContinuityMichael Frank
 
Automating the real-user scenarios across multi-apps, and multi-devices
Automating the real-user scenarios across multi-apps, and multi-devicesAutomating the real-user scenarios across multi-apps, and multi-devices
Automating the real-user scenarios across multi-apps, and multi-devicesAnand Bagmar
 

Similar to Battery Optimization for Android Apps - Devoxx14 (20)

Daily monitoring cbm of switchyard equipments through android app
Daily monitoring cbm of switchyard equipments through android appDaily monitoring cbm of switchyard equipments through android app
Daily monitoring cbm of switchyard equipments through android app
 
appium backdoors
appium backdoorsappium backdoors
appium backdoors
 
That's Web? Extreme Optimization for the Mobile Web (Oct 2012)
That's Web? Extreme Optimization for the Mobile Web (Oct 2012)That's Web? Extreme Optimization for the Mobile Web (Oct 2012)
That's Web? Extreme Optimization for the Mobile Web (Oct 2012)
 
Android Application Optimization: Overview and Tools - Oref Barad, AVG
Android Application Optimization: Overview and Tools - Oref Barad, AVGAndroid Application Optimization: Overview and Tools - Oref Barad, AVG
Android Application Optimization: Overview and Tools - Oref Barad, AVG
 
Greach 19 - Micronaut Performance
Greach 19 - Micronaut PerformanceGreach 19 - Micronaut Performance
Greach 19 - Micronaut Performance
 
Session 4708 - Omegamon for CICS customer experience at Garanti Technology
Session 4708 - Omegamon for CICS customer experience at Garanti TechnologySession 4708 - Omegamon for CICS customer experience at Garanti Technology
Session 4708 - Omegamon for CICS customer experience at Garanti Technology
 
Samsung Developer's Conference - Maximize App Performance while Minimizing Ba...
Samsung Developer's Conference - Maximize App Performance while Minimizing Ba...Samsung Developer's Conference - Maximize App Performance while Minimizing Ba...
Samsung Developer's Conference - Maximize App Performance while Minimizing Ba...
 
Testing Mobile App Performance
Testing Mobile App PerformanceTesting Mobile App Performance
Testing Mobile App Performance
 
DevOps for Developers
DevOps for DevelopersDevOps for Developers
DevOps for Developers
 
Automated Irrigation
Automated IrrigationAutomated Irrigation
Automated Irrigation
 
Google App engine
Google App engineGoogle App engine
Google App engine
 
Virtualization & Network Connectivity
Virtualization & Network Connectivity Virtualization & Network Connectivity
Virtualization & Network Connectivity
 
Acting on Real-time Behavior: How Peak Games Won Transactions
Acting on Real-time Behavior: How Peak Games Won TransactionsActing on Real-time Behavior: How Peak Games Won Transactions
Acting on Real-time Behavior: How Peak Games Won Transactions
 
Developing Mobile Apps for Performance - Swapnil Patel, Verizon Media
Developing Mobile Apps for Performance - Swapnil Patel, Verizon MediaDeveloping Mobile Apps for Performance - Swapnil Patel, Verizon Media
Developing Mobile Apps for Performance - Swapnil Patel, Verizon Media
 
IOT BASED CASHLESS PETROL PUMP
IOT BASED CASHLESS PETROL PUMPIOT BASED CASHLESS PETROL PUMP
IOT BASED CASHLESS PETROL PUMP
 
Syllabus tablet repair
Syllabus tablet repairSyllabus tablet repair
Syllabus tablet repair
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android Development
 
Five Meteor Dev Power Tools - 2015-04-06
Five Meteor Dev Power Tools - 2015-04-06Five Meteor Dev Power Tools - 2015-04-06
Five Meteor Dev Power Tools - 2015-04-06
 
Azure Site Recovery Loves Business Continuity
Azure Site Recovery Loves Business ContinuityAzure Site Recovery Loves Business Continuity
Azure Site Recovery Loves Business Continuity
 
Automating the real-user scenarios across multi-apps, and multi-devices
Automating the real-user scenarios across multi-apps, and multi-devicesAutomating the real-user scenarios across multi-apps, and multi-devices
Automating the real-user scenarios across multi-apps, and multi-devices
 

Recently uploaded

Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 

Recently uploaded (20)

Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 

Battery Optimization for Android Apps - Devoxx14

  • 1. Battery Optimization for Android Apps Murat AYDIN STM #DV14 #BatteryOptimization @maydintr
  • 2. About Me • Android Developer and blogger in his free time • Senior Software Developer at work • GDG Ankara member www.androiddeveloperdays.com • Author #DV14 #BatteryOptimization @maydintr
  • 3. Why Battery is Important? • Limited and main resource for device to function • Device may be needed for an important task when the battery is running out of power #DV14 #BatteryOptimization @maydintr
  • 4. Why Battery is Important? • Part of user experience • Bad user reviews and ratings #DV14 #BatteryOptimization @maydintr
  • 5. What to do? • Buy extended batteries • Buy case batteries • Carry external batteries Trontium-reactor can charge phones 50 times-299$ • Carry solar charges #DV14 #BatteryOptimization @maydintr
  • 6. What consumes the most? Derived from Jeff Sharkey’s presentation #DV14 #BatteryOptimization @maydintr
  • 7. Usage Measurements For a 1150mAh battery: • Watching YouTube videos: 340mA 1150/340=3.4 hours • Browsing 3G web: 225mA 1150/225=5 hours • Typical usage,10 minute for every hour:42mA=32 hours • EDGE completely idle: 5mA=9.5 days • Airplane mode idle:2mA=24 days #DV14 #BatteryOptimization @maydintr
  • 8. Bulk Data Transfer Bulk data transfer for a 6MB song: • EDGE (90kbps):300mA*9.1 min = 45 mAh • 3G (300kbps):210mA*2.7 min = 9.5 mAh • WiFi (1Mbps):330mA*48 sec = 4.4 mAh #DV14 #BatteryOptimization @maydintr
  • 9. • Research by Purdue University into energy consumption by apps (March 2012) “Free apps like Free Chess and Angry Birds spend under 25-35 percent of their energy on game play, but over 65-75 percent on user tracking, uploading user information and downloading ads.” #DV14 #BatteryOptimization @maydintr
  • 10. Radio State Machine #DV14 #BatteryOptimization @maydintr
  • 11. Bundled vs Unbundled Transfers • Suppose 3 data transfer each 3s in every 20s • Unbundled 1 data transfer = 3s+5s+12s=20s • 20s x 3 totally 60s • Bundled 9s+5s+12s = totally 26s #DV14 #BatteryOptimization @maydintr
  • 12. Prefetch Data • Reduce download times • Minimize in-app latency • Dont use it aggressively • Prefetch data such that you will only need to initiate another download every 2 to 5 minutes, and in the order of 1 to 5 megabytes #DV14 #BatteryOptimization @maydintr
  • 13. Batch Data • Create a pending transfer queue • Transfer from the queue when there is scheduled updates #DV14 #BatteryOptimization @maydintr
  • 14. Use Traffic Stats API TrafficStats.setThreadStatsTag(0xF00D); try { // Make network request using HttpClient.execute() } finally { TrafficStats.clearThreadStatsTag(); } #DV14 #BatteryOptimization @maydintr
  • 15. Polling? • Use GCM instead of polling • Use Inexact Repeating Alarms for pollings • Dont use _WAKEUP versions of alarm types • Implement exponential back-off pattern for pollings #DV14 #BatteryOptimization @maydintr
  • 16. Cache Data • Cache as much as possible • Be careful about displaying stale data Monitor Connectivity • Avoid connection attempts if there is no network • Modify download pattern based on the connectivity type #DV14 #BatteryOptimization @maydintr
  • 17. Compress Data • Compress data before transferring • Especially textual data import java.util.zip.GZIPInputStream; HttpGet request = new HttpGet(“http://url”); HttpResponse resp = new DefaultHttpClient().execute(request); HttpEntity entity = response.getEntity(); InputStream compressed = entity.getContent(); InputStream rawData = new GZIPInputStream(compressed); #DV14 #BatteryOptimization @maydintr
  • 18. Compress Data Derived from Jeff Sharkey’s presentation #DV14 #BatteryOptimization @maydintr
  • 19. Battery Monitoring • Monitor changes in charging state • Monitor Significant Changes in Battery Level • Maximize update rate when device is charging, minimize when discharging • Decrease update frequency when the battery is low #DV14 #BatteryOptimization @maydintr
  • 20. Wakelock • Q: What is wakelock? • A: A wake lock is a mechanism to indicate that your application needs to have the device stay on • Device battery life will be significantly affected by the use of this API. Do not acquire PowerManager.WakeLocks unless you really need them, use the minimum levels possible, and be sure to release them as soon as possible. #DV14 #BatteryOptimization @maydintr
  • 21. Wakelock • Use keepScreenOn instead of wakelock #DV14 #BatteryOptimization @maydintr
  • 22. Derived from Jeff Sharkey’s presentation #DV14 #BatteryOptimization @maydintr
  • 23. GPS • Use coarse network location if possible #DV14 #BatteryOptimization @maydintr
  • 24. Trepn Profiler • Real-time overlay-mode allows developers to see the impact of their actions on performance • Helps developers optimize code for CPU, power usage and network usage • Profiles the entire system or a single app • Displays accurate battery power readings with charts • Supports offline analysis of data • Can be started or stopped from a script for Automated tests • Eclipse plug-in #DV14 #BatteryOptimization @maydintr
  • 26. As a Result #DV14 #BatteryOptimization @maydintr
  • 27. Questions? • Twitter: @maydintr • Email: maydin@gmail.com • Web: www.ottodroid.net #DV14 #BatteryOptimization @maydintr