有时可能无法获得可靠的供电,停电会打断充电计划。通过对电池使用情况进行基准化分析、避免唤醒锁、设置任务计划以及监控传感器请求来防止不必要地消耗用户电池。
降低电池消耗
您可以采取多个步骤,帮助确保您的应用仅在需要时消耗电池电量,并且不会消耗不必要的电量。
- 在后台运行以及当设备靠电池电量运行时,您的应用应最大限度地减少 activity。
- GPS 等传感器会消耗大量的电池电量。为避免这些问题,您可以使用
FusedLocationProvider
API 来管理底层定位技术。它不仅可提供简单的 API,以便您从高层次角度指定高准确率或低能耗等要求;而且还可以通过缓存位置信息和批处理跨应用请求来优化设备的电池电量消耗。如需详细了解请求获取位置信息的理想方法,请参阅获取最近一次的已知位置培训指南。 - 唤醒锁定是让设备保持运行状态以便执行后台 activity 的机制。请避免使用唤醒锁定,因为其会阻止设备进入低能耗状态。
- 要想减少设备的唤醒次数,请对网络 activity 进行批处理。如需了解有关批处理的详细信息,请参阅有关优化下载以实现高效网络访问的 Android 培训内容。
- WorkManager 会调度任务并允许系统批量操作。这大大简化了常见模式的实现,如等待网络连接、设备充电状态、重试和退避。在设备正在充电并连接到不按流量计费的网络时,使用 WorkManager 执行非必需的后台活动。
- 有关网络 activity 如何消耗电池电量以及如何解决此问题的详细信息,请参阅减少网络耗电量。
对电池使用情况进行基准化分析
对应用在受控环境下的电池使用情况进行基准化分析有助于您了解在应用内执行哪些任务的电池消耗较大。通过对应用的电池使用情况进行基准化分析来衡量效率和追踪随时间变化的情况是一种很好的做法。 Batterystats 会收集应用的电池数据,而 Battery Historian 会将这些数据转换为 HTML 可视化图表。
如需详细了解如何减少电池用量,请参阅有关优化电池续航时间的 Android 培训内容。
相关内容

Case study
Marvel Strike Force and Google Play Instant join forces to improve install rate
Founded in 2017, FoxNext Games was created to expand the universes of cherished franchises like The Simpsons, Alien, Ice Age, and Avatar through interactive and immersive next-generation storytelling.

Case study
OneSoft uses instant apps to boost Galaxy Attack install rate by 15%
With over 50 million reported installs and more than 500,000 five-star ratings, Galaxy Attack is a popular alien shooter game.

Case study
Evino attracts new customers with Google Play Instant
With more than a million app customers, Evino is an innovative online wine business based in Brazil.

Case study
Ultimate Guitar takes advantage of 10MB limit for instant apps and improves install rate by 8%
With chords and tabs for over 1.1 million songs, Ultimate Guitar (UG) is one of the fastest growing guitarist communities in the world.

Case study
Rakuten Viki increases watch time 5x with Google Play Instant
Rakuten Viki, home of Viki Originals and the annual Soompi Awards, is a premier destination for multicultural youth entertainment and the worlds leading platform for Asian TV shows, movies, and influencer videos – translated into 200+ languages by a community of avid fans.

Case study
King improves player acquisition with Google Play Instant
King is a leading interactive entertainment company, with popular mobile games such as Candy Crush Saga, Farm Heroes Saga and Bubble Witch 3 Saga.