summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrevor Johns <trevorjohns@google.com>2015-05-12 14:33:38 -0700
committerTrevor Johns <trevorjohns@google.com>2015-05-12 14:33:38 -0700
commit20d9500115e9ded1dbcdfa808da603dae0e1b905 (patch)
treed04ff70d65e3a61252abf9eb6aa46ff57fcac387
parent86ed92ac001e839d2ef655d8cfcc2bd3e1829f0a (diff)
downloadandroid_development-20d9500115e9ded1dbcdfa808da603dae0e1b905.tar.gz
android_development-20d9500115e9ded1dbcdfa808da603dae0e1b905.tar.bz2
android_development-20d9500115e9ded1dbcdfa808da603dae0e1b905.zip
Sync sample prebuilts for lmp-mr1-ub-docs
Synced to //developers/samples/android commit 7e6f96a4bd8d07daf2f9e464dad32e7daa62999b Change-Id: I3c44d32aca1a5513f52e71f28d1848a055d03aab
-rw-r--r--samples/browseable/AlwaysOn/AndroidManifest.xml6
-rw-r--r--samples/browseable/AlwaysOn/src/com.example.android.wearable.wear.alwayson/MainActivity.java9
2 files changed, 13 insertions, 2 deletions
diff --git a/samples/browseable/AlwaysOn/AndroidManifest.xml b/samples/browseable/AlwaysOn/AndroidManifest.xml
index c0fce9f27..12c4b03a5 100644
--- a/samples/browseable/AlwaysOn/AndroidManifest.xml
+++ b/samples/browseable/AlwaysOn/AndroidManifest.xml
@@ -30,6 +30,12 @@
<!--If you want your app to run on pre-22, then set required to false -->
<uses-library android:name="com.google.android.wearable" android:required="false" />
+ <!--
+ To update the screen more than once per minute in ambient mode, developers should set
+ the launch mode for the activity to single instance. Otherwise, the AlarmManager launch
+ intent will open a new activity every time the Alarm is triggered rather than reusing
+ the same (already active) Activity.
+ -->
<activity android:name="com.example.android.wearable.wear.alwayson.MainActivity"
android:label="@string/app_name"
android:launchMode="singleInstance"
diff --git a/samples/browseable/AlwaysOn/src/com.example.android.wearable.wear.alwayson/MainActivity.java b/samples/browseable/AlwaysOn/src/com.example.android.wearable.wear.alwayson/MainActivity.java
index 51f287d81..0eb7f470d 100644
--- a/samples/browseable/AlwaysOn/src/com.example.android.wearable.wear.alwayson/MainActivity.java
+++ b/samples/browseable/AlwaysOn/src/com.example.android.wearable.wear.alwayson/MainActivity.java
@@ -255,10 +255,15 @@ public class MainActivity extends WearableActivity {
long timeMs = System.currentTimeMillis();
if (isAmbient()) {
- /** Prevents time drift while calculating trigger time (based on state). */
+ /** Calculate next trigger time (based on state). */
long delayMs = AMBIENT_INTERVAL_MS - (timeMs % AMBIENT_INTERVAL_MS);
long triggerTimeMs = timeMs + delayMs;
+ /**
+ * Note: Make sure you have set activity launchMode to singleInstance in the manifest.
+ * Otherwise, it is easy for the AlarmManager launch intent to open a new activity
+ * every time the Alarm is triggered rather than reusing this Activity.
+ */
mAmbientStateAlarmManager.cancel(mAmbientStatePendingIntent);
mAmbientStateAlarmManager.setExact(
AlarmManager.RTC_WAKEUP,
@@ -266,7 +271,7 @@ public class MainActivity extends WearableActivity {
mAmbientStatePendingIntent);
} else {
- /** Prevents time drift. */
+ /** Calculate next trigger time (based on state). */
long delayMs = ACTIVE_INTERVAL_MS - (timeMs % ACTIVE_INTERVAL_MS);
mActiveModeUpdateHandler.removeMessages(MSG_UPDATE_SCREEN);