androidwear-osandroid-wear-2.0ambient

Android Wear - Show watchface while ambient, app while active


I'm designing an android app for my wearable device in which I have overridden ambient mode. I would like for my app to show the watchface while in ambient mode, and show the app while out of ambient mode. In other words, I want to make the app "invisible" while ambient mode is on. (Note that keeping the activity in the foreground while this is happening is desirable!)

I have looked but haven't found a way to show the watch face while the app is open. Can anyone direct me to some sources/provide an explanation as to how one might accomplish this?


Solution

  • I'm not sure why you want to keep the activity in the foreground when the watch is in ambient mode, but I think there's a better way to do it:

    1) If you want your app to keep doing something (read from sensors etc) while in ambient mode, use a Service instead.

    2) If you just want to keep the state of your activity, save it to a Bundle and use that to repopulate the UI when the app is launched again.

    Keeping the activity alive when it's not shown is a waste of both memory and battery.

    I suggest changing your activity to only show in interactive mode. Let the system kill it when the device goes into ambient mode. Then your watch face will be displayed automatically. You can launch the app again from your watch face when interactive mode is triggered.