The Android Wear platform is flexible enough
to allow your app to display information to the user
whenever it's useful.
Now, this includes sharing fitness information, travel
updates, or to-do lists for as long
as the user might need them.
However, doing this in the usual fashion
means keeping the screen on full brightness
and providing constant updates.
This can have a big impact on battery life.
But with Always-On, your app can present useful information
while the watch is in ambient mode,
keeping your user informed while also saving precious power.
Hi, I'm Timothy Jordan.
And this is a quick introduction to keeping your Android Wear
app always on.
Android Wear operates in two primary states--
interactive and ambient.
When in interactive mode, the watch
can display full color with fluid animation
and can respond to user interactivity.
This is typically when the user is giving focused attention
to their watch.
Ambient mode is a low power state
that uses a limited color palette is
updated less frequently.
This is the typical state for the watch
while the user goes about their day.
Always-On simply allows your app to stay in the foreground
while the watch is in ambient mode.
Think of it like this.
Your user is in the grocery store and loads
your app to get their shopping list.
They see they need milk and head to the dairy aisle.
After a few moments, the watch goes into ambient mode.
Previously, your app would have closed
and the watch face would take the foreground.
However, now that you've implemented Always-On,
you get to continue displaying relevant information
to the user.
It's the best of both worlds.
The user gets to continue using your app,
while also maintaining battery life.
Before we dive into the API specifics,
let's look at a few quick design considerations.
The update frequency you choose can
be the difference between a great experience
and losing any power saving value Always-On has to offer.
Although you can choose any frequency between, say, 10
in 60 seconds, the default is 60.
And you should only change it if your app needs it to be useful.
For example, a shopping app is fine at the default,
whereas most fitness apps will want to update more frequently.
Another important battery life consideration
is how many pixels you light up and what color you use.
More pixels means more power.
You should use grayscale colors and keep around
95% of the screen black.
This is especially important to prevent
burn-in for OLED screens, but also signals to the user
that they're actually in ambient mode
and they'll need to wake up the watch
before they can interact with it.
It's also important to avoid presenting
any buttons or other interactive elements
when the watch is in ambient mode.
Touching the screen will actually bring the user back
to interactive mode.
It won't trigger the button.
One last thing.
Consider the user's privacy when displaying data
in ambient mode.
For example, keeping a messaging app on the screen
could be convenient for a user who
is in an ongoing conversation.
But displaying personal messages on the screen
for an extended period of time might bother some users.
Consider removing potentially private data
after a short period of being in ambient mode,
or refrain from showing sensitive data in ambient mode
at all.
Adding Always-On to your app is simply
a task of implementing a different view mode.
Here are the four primary things you've got to do to set up.
You currently need API level 22 or higher, or level 20 and up
if you plan to support backwards compatibility.
Make sure you have these dependencies in your gradle
build file.
Add the wearable shared library in the wearable app manifest.
And add the WAKE LOCK permission to the handheld and wearable
app manifests.
That's it.
Now you're ready to start coding.
You'll want to create the Always-On activity.
It should extend wearable activity.
In the onCreate method of this activity,
call setAmbientEnabled.
When the watch switches to ambient mode,
the system calls the onEnterAmbient method.
Override this method to update your UI to a more basic view.
Don't move anything around.
You'll want to keep the same layout.
But you'll transform into a limited color palette,
stop using anti-aliasing, and remove interactive controls
such as buttons and so on.
When the user taps the screen or brings up their wrist,
the activity switches from ambient to interactive mode,
and the system calls the onExitAmbient method.
Here you can switch back to your full color interactive layout.
While the activity is in ambient mode,
the system will periodically call onUpdateAmbient.
The default is once every minute,
though you can create an alarm manager to update
the screen more frequently.
You might do this for a running app that
displays the elapsed runtime or current pace.
However, to realize the battery saving benefits
of ambient mode, avoid updating the screen more than once
every 10 seconds.
Take a look at the documentation for more details and sample
code for building great Always-On experiences.
Remember, the user experience you
build for Wear gets to take advantage of the power
and flexibility of the android platform,
along with some special functionality just
for the wearable experience.
It's easy to get started and possible to create
truly groundbreaking UI for your users.
Giving them an experience that they want when they want,
whether that's in interactive mode or just a glance
at the ambient screen.
I'm Timothy Jordan, and I look forward
to seeing your app Always-On.
[MUSIC PLAYING]