Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 406daa44 authored by Doug Kramer's avatar Doug Kramer Committed by Android (Google) Code Review
Browse files

Merge "docs: Battery performance, networking analysis and optimization" into mnc-docs

parents adde150c 28be3259
Loading
Loading
Loading
Loading
+272 KiB
Loading image diff...
+119 KiB
Loading image diff...
+139 KiB
Loading image diff...
+15 −6
Original line number Diff line number Diff line
page.title=Optimizing Battery Life
page.tags=network,internet
page.tags=battery,network,internet
page.metaDescription=Learn how to optimize your app to reduce battery drain and use power-hungry resources efficiently.

page.article=true

trainingnavtop=true
startpage=true
@@ -23,12 +26,13 @@ startpage=true
</div>

<p>For your app to be a good citizen, it should seek to limit its impact on the battery life of its
host device. After this class you will be able to build apps that modify their functionality
and behavior based on the state of the host device.</p>
device. After this class you will be able to build apps that modify their functionality
and behavior based on the state of its device.</p>

<p>By taking steps such as disabling background service updates when you lose connectivity, or
reducing the rate of such updates when the battery level is low, you can ensure that the impact of
your app on battery life is minimized, without compromising the user experience.</p>
<p>By taking steps such as batching network requests, disabling background service updates when you
lose connectivity, or reducing the rate of such updates when the battery level is low, you can
ensure that the impact of your app on battery life is minimized, without compromising the user
experience.</p>

<h2>Lessons</h2>

@@ -37,6 +41,11 @@ These should be short and to the point. It should be clear from reading the summ
will want to jump to a lesson or not.-->

<dl>
  <dt><b><a href="{@docRoot}training/performance/battery/network/index.html">Reducing Network Battery
Drain</a></b></dt>
  <dd>Learn how to analyze your app's use of network resources and optimize it to reduce
power consumption.</dd>

  <dt><b><a href="doze-standby.html">Optimizing for Doze and App Standby</a></b></dt>
  <dd>Learn how to test and optimize your app for the power-management features introduced in
  Android 6.0 Marshmallow.</dd>
+100 −0
Original line number Diff line number Diff line
page.title=Optimizing General Network Use
trainingnavtop=true

@jd:body

<div id="tb-wrapper">
<div id="tb">

<h2>This lesson teaches you to</h2>
<ol>
  <li><a href="#compress-data">Compress Data</a>
  <li><a href="#cache-locally">Cache Files Locally</a></li>
  <li><a href="#pre-fetch">Optimize Pre-Fetch Cache Size</a></li>
</ol>

</div>
</div>

<p>
  In general, reducing the amount of network traffic helps reduce battery drain.
  In addition to the battery-optimization techniques of the previous lessons,
  you should look at these general-purpose techniques and see if you can apply
  them to your app.
</p>

<p>
  This lesson briefly covers techniques that you can use to lower network traffic and
  consequently reduce the battery drain caused by your app.
</p>

<h2 id="compress-data">Compress Data</h2>

<iframe width="448" height="252"
    src="//www.youtube.com/embed/IwxIIUypnTE?autohide=1&amp;showinfo=0"
    frameborder="0" allowfullscreen=""
    style="float: right; margin: 0 0 20px 20px;"></iframe>


<p>
  Reducing the amount of data sent or received over a network connection also
  reduces the duration of the connection, which conserves battery. You can:
</p>

<ul>
  <li>Compress data, using a compression technique such as GZIP compression.</li>

  <li>Use succinct data protocols. While JSON and XML offer human-readability, and
    language-flexibility, they are bandwidth-heavy formats, with
    high serialization costs in the Android platform. Binary serialization formats,
    such as <a href="https://developers.google.com/protocol-buffers/">Protocol Buffers</a> or
    <a href="https://google.github.io/flatbuffers/">FlatBuffers</a> offer a smaller on-the-wire
    packet size, as well as faster encoding and decoding time. If your application transfers a lot
    of serialized data on a regular basis, these formats can yield benefits for decoding time and
    transfer size.
  </li>
</ul>


<h2 id="cache-locally">Cache Files Locally</h2>

<iframe width="448" height="252"
    src="//www.youtube.com/embed/7lxVqqWwTb0?autohide=1&amp;showinfo=0"
    frameborder="0" allowfullscreen=""
    style="float: left; margin: 0 20px 20px 0;"></iframe>


<p>
  Your app can avoid downloading duplicate data by caching. Always cache static resources,
  including on-demand downloads such as full size images, and cache them for as long as reasonably
  possible.
</p>

<p>
  For example, you should consider this approach for a networked app that displays data from
  user-initiated network requests as the primary content on the screen. When the user opens this
  screen the first time, the app should display a splash screen. Subsequent loads should initially
  load with the data that was cached from the last network request. The screen reloads with
  new data once the network request is complete.
</p>

<p>
  To learn about caching, watch the video. To implement caching in your app, see <a href=
  "{@docRoot}training/efficient-downloads/redundant_redundant.html#LocalCache">Cache Files
  Locally</a>.
</p>


<h2 id="pre-fetch">Optimize Pre-Fetch Cache Size</h2>

<p>
  Optimize pre-fetch cache size based on local file system size and current network connectivity.
  You can use the connectivity manager to determine what type of networks (Wi-FI, LTE, HSPAP, EDGE,
  GPRS) are active and modify your pre-fetching routines to minimize battery load.
</p>

<p>
  For more information, see
  <a href="{@docRoot}training/efficient-downloads/connectivity_patterns.html#Bandwidth">Use
  Modifying your Download Patterns Based on the Connectivity Type</a>.
</p>
Loading