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 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" ...