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

Commit 22eb26c2 authored by Bert McMeen's avatar Bert McMeen Committed by android-build-merger
Browse files

Merge \\"Docs: Watch face performance update\\" into mnc-io-docs am: 99677fb4

am: 106af828

Change-Id: Ia9fa224a4ebb6e51a3c6141751036504d202e137
parents 5b4ff21a 106af828
Loading
Loading
Loading
Loading
+94 −43
Original line number Diff line number Diff line
@@ -6,30 +6,117 @@ page.title=Optimizing Performance and Battery Life
<div id="tb">
<h2>This lesson teaches you to</h2>
<ol>
  <li><a href="#Basic">Basic Optimization</a></li>
  <li><a href="#Animations">Best Practices for Animations</a></li>
  <li><a href="#ReduceSize">Reduce the Size of Your Bitmap Assets</a></li>
  <li><a href="#CombineBitmaps">Combine Bitmap Assets</a></li>
  <li><a href="#AntiAlias">Disable Anti-Aliasing when Drawing Scaled Bitmaps</a></li>
  <li><a href="#OutDrawing">Move Expensive Operations Outside the Drawing Method</a></li>
  <li><a href="#SavePower">Follow Best Practices to Save Power</a></li>
</ol>
<h2>You should also read</h2>
<ul>
  <li><a href="{@docRoot}design/wear/watchfaces.html">Watch Faces for Android Wear</a></li>
  <li><a href="http://android-developers.blogspot.com/2014/12/making-performant-watch-face.html">
Making a performant watch face</a></li>
  <li><a href="http://android-developers.blogspot.com/2016/04/deprecation-of-bindlistener.html">
Deprecation of BIND_LISTENER with Android Wear APIs</a></li>
</ul>
</div>
</div>

<p>In addition to accommodating notification cards and system indicators, you need to ensure that
the animations in your watch face run smoothly and that your service does not perform unnecessary
computations. Watch faces in Android Wear run continuously on the device, so it is critical
that your watch face uses power efficiently.</p>
<p>This lesson has tips for conserving power and improving performance.
A watch face runs continuously, so it must use power
efficiently. </p>

<p>This lesson provides some tips to speed up your animations and to measure and conserve
power on the device.</p>
<p>Services must not perform unnecessary computations.
Watch faces with animations must run smoothly while accommodating
notification cards and system indicators.</p>

<h2 id="Basic">Basic Optimization</h2>

<p>This section contains best practices for improving efficiency during
periods when a watch face is inactive.</p>

<h3>Use callbacks in WatchFaceService.Engine</h3>

<p>Ensure that your watch face performs
computations only when active; use callbacks
in <a href="{@docRoot}reference/android/support/wearable/watchface/
WatchFaceService.Engine.html">{@code WatchFaceService.Engine}</a>.
Preferably, use the following methods of that class to determine if
the watch face is visible:</p>

<ul>
  <li>{@code onVisibilityChanged(boolean)}</li>
  <li>{@code isVisible()}</li>
</ul>

<p>Alternatively, use the following methods of the same class
(<a href="{@docRoot}reference/android/support/wearable/watchface/
WatchFaceService.Engine.html">{@code WatchFaceService.Engine}</a>):</p>

<ul>
  <li>{@code onCreate()}</li>
  <li>{@code onDestroy()}</li>
</ul>

<h3>Use listeners registered with the DataApi interface</h3>

<p>To listen for events, use live listeners that are registered
with <a href="https://developers.google.com/android/reference/com/google/
android/gms/wearable/DataApi.html#addListener
(com.google.android.gms.common.api.GoogleApiClient, com.
google.android.gms.wearable.DataApi.DataListener)">{@code DataApi.addListener}</a>.
For an example, see <a href="{@docRoot}training/wearables/data-layer/
data-items.html#ListenEvents">Syncing Data Items</a>.</p>

<p>Do not use <a href="https://developers.google.com/
android/reference/com/google/android/gms/wearable/
WearableListenerService">{@code WearableListenerService}</a> to listen for
events, because it is
called whether or not a watch face is active. For more information, see
<a href="http://android-developers.blogspot.com/2016/04/
deprecation-of-bindlistener.html">Deprecation of BIND_LISTENER
with Android Wear APIs</a>.</p>

<p>Do not register a broadcast receiver in the Android manifest file
to get system events such as time zone changes, battery events, etc., because
the <a href="{@docRoot}reference/android/content/BroadcastReceiver.html">{@code BroadcastReceiver}</a>
is called whether or not a watch face is active. However, you can use the
<a href="{@docRoot}reference/android/content/Context.html#registerReceiver(android.
content.BroadcastReceiver, android.content.IntentFilter)">{@code registerReceiver}</a> method
of the {@code Context} class to register a receiver.</p>

<h3>Monitor power consumption</h3>

<p>The <a href="https://play.google.com/store/apps/details?id=com.google.android.wearable.app&hl=en">
Android Wear companion app</a> enables developers and users to see how much battery
is consumed by different processes
on the wearable device (under <strong>Settings</strong> > <strong>Watch
battery</strong>).</p>

<p>For information about features introduced in Android 5.0 that help you improve battery life,
see <a href="{@docRoot}about/versions/android-5.0.html#Power">Project Volta</a>.</p>

<h2 id="Animations">Best Practices for Animations</h2>

<p>The best practices in this section help to reduce the power consumption of animations.</p>

<h3>Reduce the frame rate of animations</h3>

<p>Animations are often computationally expensive and consume a significant amount of power. Most
animations look fluid at 30 frames per second, so you should avoid running your animations
at a higher frame rate.</p>

<h3>Let the CPU sleep between animations</h3>

<p>Animations and small changes to the contents of the watch face wake up the CPU. Your watch
face should let the CPU sleep in between animations. For example, you can use short bursts of
animation every second in interactive mode and then let the CPU sleep until the next second.
Letting the CPU sleep often, even briefly, can significantly reduce power consumption.</p>

<p>To maximize battery life, use animations sparingly. Even a blinking colon wakes up the CPU with
every blink and hurts battery life.</p>

<h2 id="ReduceSize">Reduce the Size of Your Bitmap Assets</h2>

@@ -68,16 +155,12 @@ by 97&#37;.</p>
<p>Reducing the size of your bitmap assets as described in this section not only improves
the performance of your animations, but it also saves power.</p>



<h2 id="CombineBitmaps">Combine Bitmap Assets</h2>

<p>If you have bitmaps that are often drawn together, consider combining them into the same
graphic asset. You can often combine the background image in interactive mode with the tick
marks to avoid drawing two full-screen bitmaps every time the system redraws the watch face.</p>



<h2 id="AntiAlias">Disable Anti-Aliasing when Drawing Scaled Bitmaps</h2>

<p>When you draw a scaled bitmap on the {@link android.graphics.Canvas} object using the {@link
@@ -139,35 +222,3 @@ implementation is short and
consistent across invocations. For more information, see
<a href="{@docRoot}tools/debugging/ddms.html">Using DDMS</a>.</p>


<h2 id="SavePower">Follow Best Practices to Save Power</h2>

<p>In addition to the techniques described in the previous sections, follow the best
practices in this section to reduce the power consumption of your watch face.</p>

<h3>Reduce the frame rate of animations</h3>

<p>Animations are often computationally expensive and consume a significant amount of power. Most
animations look fluid at 30 frames per second, so you should avoid running your animations
at a higher frame rate.</p>

<h3>Let the CPU sleep</h3>

<p>Animations and small changes to the contents of the watch face wake up the CPU. Your watch
face should let the CPU sleep in between animations. For example, you can use short bursts of
animation every second in interactive mode and then let the CPU sleep until the next second.
Letting the CPU sleep often, even briefly, can significantly reduce power consumption.</p>

<p>To maximize battery life, use animations sparingly. Even a blinking colon wakes up the CPU with
every blink and hurts battery life.</p>

<h3>Monitor power consumption</h3>

<p>The <a href="https://play.google.com/store/apps/details?id=com.google.android.wearable.app&hl=en">
Android Wear companion app</a> lets developers and users see how much battery different processes
on the wearable device are consuming under <strong>Settings</strong> > <strong>Watch
battery</strong>.</p>

<p>For more information about new features in Android 5.0 that help you improve battery life,
see <a href="{@docRoot}about/versions/android-5.0.html#Power">Project Volta</a>.</p>