O'Reilly logo

Mastering Android Wear Application Development by Javeed Chida, Siddique Hameed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

An always running step counter

Now, let's demonstrate everything we presented in the previous section in practice by augmenting our step counter from Chapter 7, Voice Interactions, Sensors, and Tracking, to be always on. Let's dive right in.

The Android manifest file

The first thing to do is to update the AndroidManifest.xml file and set up the StepCounterActivity class to have its launchMode set to singleInstance. This is necessary in order to update the screen more than once per minute in ambient mode. Not doing so will cause the AlarmManager class to launch an intent to open a new activity every time the alarm is triggered rather than reusing the same (already active) activity. Here is the snippet from the file:

<activity android:name=".StepCounterActivity" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required