0

I have a service that does some extra work for android wear. I want to invoke the extra work only when the user is seeing my watch face.

One way to detect that the watch face is being invoked is by using the sendMessageAPI and a message will come.

How to know when the watchface has been changed?

Is message the only way to achieve this or there is some clean function given by the WearAPIs?

Thanks in Advance.

nizam.sp
  • 4,002
  • 5
  • 39
  • 63

1 Answers1

1

When the user chooses your watch face, the WatchFaceService.Engine subclass will receive onCreate callback and when it is stopped being used, it will receive onDestroy callback. Do the work between these two callbacks.

gruszczy
  • 40,948
  • 31
  • 128
  • 181
  • Thank you. Yes. I tried sending a message on oncreate. It works fine. But, in ondestroy, message is not being sent but a log line is possible. How do I intimate the phone that the watchface is destroyed? I assume sharedpreferences are not across watch and app. – nizam.sp Jun 27 '15 at 19:15
  • I wouldn't use messages for that, because they are not reliable. You should be using data items instead. I would recommend this: when you get onCreate, start an intent service, that will post a data item with the information that the watch face is being used. When you get onDestroy, start the same intent service, but take a different action and destroy the data item. – gruszczy Jun 27 '15 at 19:55