Permission required error with new Timer() in Backgroundservice

Hi!

In System.ServiceDelegate initialize() and onTemporalEvent() functions this code:
var timer = new Timer.Timer();

gives
Permission requiredFailed invoking <symbol>


Is this a bug or timers cannot be used in ServiceDelegate?
  • Timers can't be used in the SeviceDelegate.

  • Well, that's unfortunate.

    How do you handle retransmissions then?
    When communicating the onError is called when there was an error sending the data. You usually retry this a couple of times but wait a couple of ms between each retry.
    How am I supposed to wait before the resend without a timer?
  • If you get an error, one cause would be if the watch and phone aren't connected. The way I handle that in a background event is if phoneConnected is false, I don't even make the request, and just return an error status. The background has at most 30 seconds when it runs, so I don't even bother retrying, and just check again the next time the temporal event runs.

    For other types of errors, can't you just retry without a delay? It's kind of a kludge, but if you want to wait a bit, you can enable sensors and then use the callback to get awakened every second or so. I experimented with this in a test app, but not production, as the app will then also need senor permissions, but not actually do anything with the sensors.

    Have you considered doing what you're trying in a widget or a watch app, where you can just do everything in the main app, use timers, etc?
  • I could try without a delay, but that is not very hardware friendly usually. The sensor trick seems very 'hacky', I'm not sure I'll try it, but nice find nonetheless :)

    I haven't. I'm writing a watchface where I display the time, and lots of other info from the phone too. Could be a watchapp, I don't know the drawbacks of making it a watchapp instead of a face. It should be the main watchface whenever the user comesback from anything (widget/app/activity, whatever).
  • Displaying the info in a widget would make it easier to implement, and it can be only a screen away from the watchface. As a watch face, I'm guessing you'll run into problems where users will want other things that are common on WFs - steps/calories/intense mins/floors/sunrise/sunset, and many more, so you may want to consider that part too.
  • Yeah, those are on the watchface too :) Though not all of them, but configurable. I'm pretty sure I'll need a real device to see what's better for this, but I know if those restrictions on communications and timer didn't exist it would definitely be a watchface.
  • Until you see the actual flow and interaction on a devices, you might not see what's best.

    (trust me.. Been there, done that with the original va and CIQ 1.0.x! :) )